Created
January 20, 2020 08:06
-
-
Save eftikharEmad/576a3d72e8e6465d7855b5478a3e5098 to your computer and use it in GitHub Desktop.
This file contains 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
ImagePicker.openPicker({ | |
width: 200, | |
height: 200, | |
cropping: true, | |
cropperCircleOverlay: true, | |
}).then(image => { | |
let options = { | |
headers: { | |
Accept: "application/json", | |
"Content-Type": "multipart/form-data", | |
...authHeaders | |
}, | |
method: "POST", | |
} | |
let body = new FormData() | |
body.append("photoable_type", "User") | |
body.append("photoable_id", user.id) | |
body.append("photo_file_name", image.filename) | |
body.append("photo[url]", image.path) | |
body.append("photo[contentType]", image.mime) | |
body.append("photo[uri]", image.path) | |
options.body = body | |
fetch("http://localhost:3000/api/v1/photos", options) | |
}).then(res => { | |
console.log("===== res ==== : ", res) | |
}) | |
}) | |
FormData type:: | |
{"_parts":[["photoable_type","User"],["photoable_id",2],["photo_file_name","IMG_0004.JPG"],["name","path-to/tmp/react-native-image-crop-picker/9B57E564-DAF2-4859-A905-1885B11C1A59.jpg"],["contentType","image/jpeg"],["url","path-to/tmp/react-native-image-crop-picker/9B57E564-DAF2-4859-A905-1885B11C1A59.jpg"]]}: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment