Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem to send file #25

Open
njtnestor opened this issue May 18, 2020 · 5 comments
Open

Problem to send file #25

njtnestor opened this issue May 18, 2020 · 5 comments

Comments

@njtnestor
Copy link

njtnestor commented May 18, 2020

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

@dotnetdreamer
Copy link
Owner

@njtnestor can you please pull this project and run the demo and check ? i havn't tested on JS...

@andresilva-cc
Copy link

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?

@vallemar
Copy link

the same here

@SidnevIgor
Copy link

Had the same problem with a request getting stuck and therefore crushing the Android app.
What I found the reason was in

body = JSON.parse(response.body().string());

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:

@timoschlueter
Copy link

i can confirm that this is an issue. Any chance that this will be fixed, @dotnetdreamer?
Would highly appreciate it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants