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

Missing headers #10

Open
Zatchou opened this issue Jul 28, 2015 · 5 comments
Open

Missing headers #10

Zatchou opened this issue Jul 28, 2015 · 5 comments

Comments

@Zatchou
Copy link

Zatchou commented Jul 28, 2015

Hello,

I don't understand why i get an error "Missing Header: Authorization" from my server.

My code :

          var ftpParams = {
                uri: uri,
                uploadUrl: "https://mycloudurl/content?"+cloudQuery
                fileName: this.state.note.generatedKey+".png",
                mimeType: "image",
                headers: {
                  "Authorization": "Bearer "+token,
                  "Content-Type": "application/x-www-form-urlencoded",
                };
                data: {},
            };

            NativeModules.FileTransfer.upload(ftpParams, (err, res) => {
              console.log(res);
              console.log(err);
            });

What did I do wrong ? Bad headers format ?

@rt2zz
Copy link
Contributor

rt2zz commented Jul 28, 2015

that looks about right, something similar works for me:

headers: {
     authorization: 'bearer '+token
},

This should not matter but maybe try lowercase 'authorization' and removing the Content-Type header.

You can also try using FormData has an alternative:
facebook/react-native#1357

@Zatchou
Copy link
Author

Zatchou commented Jul 30, 2015

It didn't works.
I test my request with a simple "nc" command, there are no headers received.

My code :

  var ftpParams = {
                      uri: url,
                      uploadUrl: "http://localhost:1234/toto?"+cloudBody,
                      fileName: fileName,
                      mimeType: "image/jpg",
                      headers:  {
                        authorization: "bearer "+token,
                      },
                      data: {
                        description: description,
                      },
                  };

My server :

POST /toto?name=hello.png&folder=bWVzIGRvc3NpZXJzIHBhcnRlbmFpcmVzL01lbWVudG9wLw HTTP/1.1
Host: localhost:1234
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=----react.file.transfer.form.boundary
Content-Length: 12144
Accept-Language: en-us
Accept: */*
Connection: keep-alive
User-Agent: mementopv2/1 CFNetwork/711.3.18 Darwin/14.3.0

------react.file.transfer.form.boundary
Content-Disposition: form-data; name="description"

{ name: hello.png,  size: 43 }
------react.file.transfer.form.boundary
Content-Disposition: form-data; name="file"; filename="hello.png"
Content-Type: image/png
Content-Length: 11817

?PNG

׌ ?IDATx??????i1?_?nq??@w @?@+         (...)

------react.file.transfer.form.boundary--

@rt2zz
Copy link
Contributor

rt2zz commented Jul 30, 2015

Ah I see the problem. The versoin on NPM is not up to date and does not have the header handling. You may want to point your npm install to the git repo, or just copy and paste it over (the only file that matters is RCTFileTransfer.m)

@Zatchou
Copy link
Author

Zatchou commented Aug 7, 2015

You did right. Thanks it works now !

@meznaric
Copy link

meznaric commented Oct 9, 2015

It would be cool if you could update version on NPM. Thanks!

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

No branches or pull requests

3 participants