Last active
December 20, 2021 05:05
-
-
Save mirsahib/ee953c17c5484ed6da261f05e6f1bd0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// createUser and readUser is only necessary for signup and sign in page | |
const createUser = async (url, data) => { | |
try { | |
let response = await fetch(url, { | |
method: "POST", | |
headers: { | |
Accept: "application/json", | |
"Content-Type": "application/json", | |
}, | |
body: JSON.stringify(data), | |
}); | |
return await response.json(); | |
} catch (err) { | |
console.log(err); | |
} | |
} | |
const readUser = async (url, data) => { | |
try { | |
let response = await fetch(url+'?email='+data.email+'&password='+data.password, { | |
method: "GET", | |
headers: { | |
Accept: "application/json", | |
"Content-Type": "application/json", | |
}, | |
}); | |
return await response.json(); | |
} catch (err) { | |
console.log(err); | |
} | |
} | |
//upload image with label data to realm | |
const uploadData = async (url, data) => { | |
try { | |
let response = await fetch(url, { | |
method: "POST", | |
headers: { | |
Accept: "application/json", | |
"Content-Type": "application/json", | |
}, | |
body: JSON.stringify(data), | |
}); | |
return await response.json(); | |
} catch (err) { | |
console.log(err); | |
} | |
} | |
//upload image to cloudinary | |
const uploadImage = async (url, uri) => { | |
try { | |
let base64Img = `data:image/jpg;base64,${uri}`//attach base64 image | |
let imageData = { file: base64Img, upload_preset: "annotationImage" } | |
let response = await fetch(url, { | |
method: "POST", | |
headers: { | |
Accept: "application/json", | |
"Content-Type": "application/json", | |
}, | |
body: JSON.stringify(imageData), | |
}); | |
return await response.json(); | |
} catch (err) { | |
console.log(err); | |
} | |
} | |
export { | |
createUser, | |
readUser, | |
uploadData, | |
uploadImage | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment