numandev1 / react-native-compressor

🗜️Compress Image, Video, and Audio same like Whatsapp 🚀✨
MIT License
890 stars 85 forks source link

when i upload file using backgroundUpload, the body inside the response is empty [ios] #263

Open segun-flexible opened 8 months ago

segun-flexible commented 8 months ago

here is the code am using to upload file to my backend, and am responding json back from the backend like this res.json({status: true, message :"File Uploaded"})

backgroundUpload( ${BASE_URL}/api/user/upload-media?id=${result.id}, file.uri, { fieldName: 'medias', mimeType: file.mediaType == "photo" ? "image/png" : mime.getType(file.uri), uploadType: UploadType.MULTIPART, httpMethod: 'POST', headers: { 'is_native_app': 'is_native_app', 'Content-Type': 'multipart/form-data', 'Authorization':Bearer ${token}` } } ).then((result => { console.log(result, "ok") const response = JSON.parse(result.body);

          if (response.status) dispatch(writtenAction.incrementWritten())
          else {
            dispatch(writtenAction.clearWritten())
            return openModal({
              title: "Something Went Wrong",
              sub: response.message,
              btnText: "Okay",
              headerImg: require("../../assets/error.png")
            })
          }
        })).catch(err => console.log(err, "error here"))
      }`

here is the response on Android Object { "body": "{\"status\":true,\"message\":\"File Uploaded\"}", "headers": Object { "Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Origin": "*", "Connection": "keep-alive", "Content-Length": "41", "Content-Type": "application/json; charset=utf-8", "Date": "Fri, 05 Jan 2024 17:25:51 GMT", "ETag": "W/\"29-WcVpNPZgUZEDrIUCox0kVl9B85A\"", "Expect-CT": "max-age=0", "Keep-Alive": "timeout=5", "Referrer-Policy": "no-referrer", "Strict-Transport-Security": "max-age=15552000; includeSubDomains", "Vary": "Accept-Encoding", "X-Content-Type-Options": "nosniff", "X-DNS-Prefetch-Control": "off", "X-Download-Options": "noopen", "X-Frame-Options": "SAMEORIGIN", "X-Permitted-Cross-Domain-Policies": "none", "X-XSS-Protection": "0", }, "status": 200, }

but on ios the body is not showing, its empty

Object { "body": "", "headers": Object { "Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Origin": "*", "Connection": "keep-alive", "Content-Length": "41", "Content-Type": "text/html; charset=utf-8", "Date": "Fri, 05 Jan 2024 17:56:57 GMT", "Etag": "W/\"29-WcVpNPZgUZEDrIUCox0kVl9B85A\"", "Expect-CT": "max-age=0", "Keep-Alive": "timeout=5", "Referrer-Policy": "no-referrer", "Strict-Transport-Security": "max-age=15552000; includeSubDomains", "Vary": "Accept-Encoding", "X-Content-Type-Options": "nosniff", "X-DNS-Prefetch-Control": "off", "X-Download-Options": "noopen", "X-Frame-Options": "SAMEORIGIN", "X-Permitted-Cross-Domain-Policies": "none", "X-XSS-Protection": "0", }, "status": 200, }

as you can see the body is empty, which am not expecting that, it show the body on android but is not showing it on ios

nikitapilgrim commented 6 months ago

same

husnain917 commented 4 months ago

I have same issue on IOS android working fine.

raghsahu commented 3 months ago

I have same issue for iOS because in Uploader.swift file return body empty sting.

let result: [String : Any] = ["status": response.statusCode, "headers": response.allHeaderFields, "body": ""]