After Image Uploading, image uri is null for iOS alone in React Native

后端 未结 1 388
臣服心动
臣服心动 2021-01-25 00:46

In my React Native app, I have added an functionality to upload multiple images, which will be stored as image[] including uri. This works perfectly for Android.

But fo

相关标签:
1条回答
  • I had this exact same issue.

    The solution is to set the uri to the 'file' attribute.

    This is how you can append the image into formData correctly for both iOS and Android:

            let uri = image.file;
    
            // extract the filetype
            let fileType = uri.substring(uri.lastIndexOf(".") + 1);
    
            formData.append('uploads[]', {
                uri,
                name: `photo.${fileType}`,
                type: `image/${fileType}`,
            });
    

    You can't remove the additional data on the iOS filename "?id=98EBA95A-254E-40F4-8E1D-C355D8795777&ext=JPG'" at this point, otherwise it won't upload. You can remove it at the server side though.

    0 讨论(0)
提交回复
热议问题