Problem to send file
njtnestor opened this issue · 5 comments
Hello I am using a Mediafilepicker to grab a file with nativescript, but as example to test I created a file of next way:
let stream = new java.io.ByteArrayOutputStream();
stream.write(5)
let file = stream.toByteArray()
After i do this:
let fd = new TNSHttpFormData();
let params = []
let param = {
data: file,
parameterName: 'file'
}
params.push(param)
try{
const response = await fd.post('https://example.com/file', params, {
headers: {
//some headers
}
});
console.log(response)
} catch(e){
console.log('error:', e)
}
As result I got my app blocked and crashed without errors
P.D: I'm using javascript instead typescript
@njtnestor can you please pull this project and run the demo and check ? i havn't tested on JS...
I can confirm that this happens to me too. I see that the POST request is made to the API, but fd.post do not return and crash the app in Android 7.1.1. In Android 10 it simply hangs forever. The strange thing is that this was working before. Any solutions for this?
the same here
Had the same problem with a request getting stuck and therefore crushing the Android app.
What I found the reason was in
When you call any methods on response object (i.e. body(), headers(), code() or message()) they are never resolved. Therefore, the solution that worked for me was to copy the whole class TNSHttpFormData (https://github.com/dotnetdreamer/nativescript-http-formdata/blob/master/src/TNSHttpFormData.android.ts) and 2 related imported files:
- https://github.com/dotnetdreamer/nativescript-http-formdata/blob/master/src/index.d.ts
- https://github.com/dotnetdreamer/nativescript-http-formdata/blob/master/src/TNSHttpFormData.common.ts
into local project and remove all instances in TNSHttpFormData where any methods were called on response object.
Example
let callback = new okhttp3.Callback({ onResponse: (call, response) => { resolve({ headers: "", statusCode: 202, statusMessage: "202", body: "" }); }, // incase of timeout etc, this will be called onFailure: (call, response) => { reject(response); } });
i can confirm that this is an issue. Any chance that this will be fixed, @dotnetdreamer?
Would highly appreciate it :)