2

I'm trying to submit form data and upload images from React Native app to CodeIgniter backend server. I'm choosing the images from react-native-image-crop-picker and only the data is sent and saved. But not the image is uploaded. I have tried this using Postman and it works perfectly.

I see that form.append() has 3 parameters. I checked the Postman request code, and it shows like this

data.append("attach_report", fileInput.files[0], "...3539240198157045_n.jpg");

My problem is, what's the datatype of fileInput.files[0] in this? Thanks in advance

1 Answer 1

1

Finally I found an answer for this. I have seen that the file returns from react-native-image-crop-picker is almost a File object. So I just edited the file like below.

// image is react-native-image-crop-picker returning file
image.uri = image.path;
image.name = "TEST.jpg";
image.type = image.mime;
image.dateModified = new Date();

Then,

const f = new FormData();
f.append('attach_report', image, image.uri);
f.append('user_id', 1);

Then submit the form. It works in my scenario...

Sign up to request clarification or add additional context in comments.

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.