0

For a project we need to upload an image file which has memory above 2mb.\ which we are not able to upload through base64 conversion.

Any help could be usefull

1
  • why not use rn-fetch-blob Commented Jul 30, 2018 at 9:45

3 Answers 3

2

Once you have your local image url using ImagePicker or some another solution, here's how you can send it to your server:

const formData = new FormData();
formData.append("image", { uri: imageUrl, name: 'image.jpg', type: 'multipart/form-data' })

fetch(yourUrl, {
    method: "POST", {
        'Content-Type': 'multipart/form-data',
    },
    body: formData
);
Sign up to request clarification or add additional context in comments.

1 Comment

The search I did to find this answer! GOD BLESS YOU!
1

Use any request library e.g axios . Then try with form data. To pick the image from device/camera you can use react-native-image-picker.

import ImagePicker from 'react-native-image-picker'

ImagePicker.showImagePicker(options, response => {
          console.log(response.data)

        });

Comments

0

Below is what helped me.

  1. In android/app/src/main/java/com/{yourProject}/MainApplication.java comment the below line :

    initializeFlipper(this, getReactNativeHost().getReactInstanceManager())
    
  2. In android/app/src/debug/java/com/{yourProject}/ReactNativeFlipper.java comment in line 43 :

    builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
    
  3. Code for image upload :

    var formData = new FormData();
       formData.append('UserId', '[email protected]');
       formData.append('VisitId', '28596');
       formData.append('EvidenceCapturedDate', '09/10/2019 13:28:20');
       formData.append('EvidenceCategory', 'Before');
       formData.append('EvidenceImage', {
         uri: Platform.OS === 'android' ? `file:///${path}` : path,
         type: 'image/jpeg',
         name: 'image.jpg',
       });
       axios({
         url: UrlString.BaseUrl + UrlString.imageUpload,
         method: 'POST',
         data: formData,
         headers: {
           Accept: 'application/json',
           'Content-Type': 'multipart/form-data'
         },
       })
         .then(function (response) {
           console.log('*****handle success******');
           console.log(response.data);
    
         })
         .catch(function (response) {
           console.log('*****handle failure******');
           console.log(response);
         });
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.