backenddev
backenddev

Reputation: 43

React Native upload image

Mobile application for upload image from Gallery / Camera , we need to ask run time permission. If permission granted, we need to use.

const data = new FormData(); data.append("file", { uri: file_parse_uri, type: "image/jpeg", name: file_parse_name, });

headers: { Authorization: 'if need', "Content-Type": "multipart/form-data", },

Upvotes: 1

Views: 280

Answers (1)

Oussama Mg
Oussama Mg

Reputation: 153

i think that you're performing the request wrong, try this instead :

Note : change the pickImage function so that the setUri takes (result.assets[0]) instead of (result.assets[0].uri)

const formBody = new FormData();
    formBody.append('image', {
        uri: uri.uri,
        name: uri.name,
        type: uri.type,
    });

then instead of passing { image : uri } next to url try to passe this : { body: formBody }

Upvotes: 4

Related Questions