I want to take a picture, save it to an album and send the image right away. (Do not select from album.)
There is no problem in taking the current picture, saving it in an album and checking the uri.
but the x-www-form-urlencoded sending process does not work properly.
I think there may be a problem with the format of sending the API.
postman is also attached. (No problem in Postman.)
takePictureAndCreateAlbum = async () => {
const { uri } = await this.camera.takePictureAsync();
console.log('uri', uri);
const asset = await MediaLibrary.createAssetAsync(uri);
console.log('asset', asset);
const filename = asset.filename;
MediaLibrary.createAlbumAsync('Expo', asset)
// POST API
.then(() => {
var file = new FormData();
file.append({file: uri});
return fetch(/* API_URL */, {
method: 'POST',
headers:{
'Content-Type':'application/x-www-form-urlencoded',
'Accept': 'application/json'
} , body : file} )
.then((response) => response.text())
.then((responseData) => {
console.log(responseData);
})
.done();
})
.catch(error => {
Alert.alert('An Error Occurred!')
});
};