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

Not able to upload file using Put operation #7

Open
sapphireroofing opened this issue Jun 17, 2021 · 12 comments
Open

Not able to upload file using Put operation #7

sapphireroofing opened this issue Jun 17, 2021 · 12 comments

Comments

@sapphireroofing
Copy link

Hi Kamranayub,

I have downloaded your postman collection and tried to perform some operations on blob. The GET operation works fine, but when I try to upload a file using PUT operation I am receiving the following error :

AuthenticationFailed Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:e0cdd282-301e-0030-656f-63747e000000 Time:2021-06-17T11:57:01.6867488Z The MAC signature found in the HTTP request '9GvSpqmVGuFV+HPPR4daDlzJV8MN6SELFrvINwgtbS0=' is not the same as any computed signature. Server used following string to sign: 'PUT

56

text/plain

x-ms-blob-type:BlockBlob
x-ms-date:Thu, 17 Jun 2021 11:57:01 GMT
x-ms-version:2017-04-17

Could you guide me on how to resolve the issue?

@BenRamins
Copy link

@sapphireroofing I faced the exact issue you're facing, I just don't remember the exact solution I used. I don't have time to dig that up right now (sorry!), but one possible solution would be to update the x-ms-version you're using.

@steveb85
Copy link

@sapphireroofing @BenRamins did either of you find a solution for this?

@BenRamins
Copy link

@sapphireroofing @BenRamins did either of you find a solution for this?

can you post your headers here?

@steveb85
Copy link

I believe I found the issue, but working on something for a fix

@steveb85
Copy link

@BenRamins On a GET request with the console I get this
Signature Parts
(16) ["GET", "", "", "", "", …]
0: "GET"
1: ""
2: ""
3: ""
4: ""
5: ""
6: ""
7: ""
8: ""
9: ""
10: ""
11: ""
12: "x-ms-date:Wed, 29 Jun 2022 20:27:07 GMT"
13: "x-ms-version:2018-03-28"
14: "/<accountname_removed>/"
15: "comp:list"

which leads to this

Signature String
"GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:Wed, 29 Jun 2022 20:27:07 GMT\nx-ms-version:2018-03-28\n/<accountname_removed>/\ncomp:list"

which is successful.

ON a PUT request this is the results

Signature Parts
(23) ["PUT", "", "", "11", "", …]
0: "PUT"
1: ""
2: ""
3: "11"
4: ""
5: "text/plain; charset=UTF-8"
6: ""
7: ""
8: ""
9: ""
10: ""
11: ""
12: "x-ms-blob-content-disposition:attachment; filename="fname.ext""
13: "x-ms-blob-type:blockblob"
14: "x-ms-date:Wed, 29 Jun 2022 20:31:54 GMT"
15: "x-ms-meta-m1:v1"
16: "x-ms-version:2021-06-08"
17: "/<accountname_removed>/sb-test/hello"
18: "content-length:undefined"
19: "content-type:undefined"
20: "x-ms-blob-content-disposition:attachment; filename="fname.ext""
21: "x-ms-blob-type:BlockBlob"
22: "x-ms-meta-m1:v1"

Which builds this, obviously causing the issue with the signature

Signature String
"PUT\n\n\n11\n\ntext/plain; charset=UTF-8\n\n\n\n\n\n\nx-ms-blob-content-disposition:attachment; filename="fname.ext"\nx-ms-blob-type:blockblob\nx-ms-date:Wed, 29 Jun 2022 20:31:54 GMT\nx-ms-meta-m1:v1\nx-ms-version:2021-06-08\n/<accountname_removed>/sb-test/hello\ncontent-length:undefined\ncontent-type:undefined\nx-ms-blob-content-disposition:attachment; filename="fname.ext"\nx-ms-blob-type:BlockBlob\nx-ms-meta-m1:v1"

I believe it's related to #6

@BenRamins
Copy link

@steveb85 try this:

x-ms-version:2017-11-09
x-ms-blob-type:BlockBlob (you have a duplicate in 13 and 21)
Content-Type:*.{filetype} (you don't have that defined)

@steveb85
Copy link

@BenRamins The duplication isn't from my headers, it's because the script isn't catching the type Content Type or Content Length at all, and then is adding them to the Canonical Items that come in the script at line 31 in postman. Content Type was defined in my headers as "text/plain charset =UTF-8" is that incorrect? Thanks for the help! Cheers

@BenRamins
Copy link

@steveb85 for a text file, here's the exact headers I use that work just fine:

headers: {
'x-ms-version': '2017-11-09',
'x-ms-date': 'Sun, 09 Jan 2022 00:30:54 GMT',
'x-ms-blob-type': 'BlockBlob',
'Content-Length': ,
'Authorization': <Your Bearer Token (if any) Here>,
'Content-Type': 'text/plain'
}

Alternatively you can take a look here: https://www.postman.com/speeding-astronaut-338068/workspace/azure-rest-api/overview
Storage Services -> Blob Service -> Operations on Blobs

I wrote it a while ago but still works - hope it helps!

@steveb85
Copy link

Thanks @BenRamins huge help. I got it to work with a little pushing around, it's a bit rudimentary and hacked but from getting it to work once, I think I can work through what I need in a script to make it work! much appreciated though.

@steveb85
Copy link

@BenRamins just looking through your speeding-astronaut postman post, very informative, it seems you choose to create a bearer token rather than using the HMACSHA256 method of encription that this postman collection does, is there any advantages / disadvantages to the two methods?

@BenRamins
Copy link

@steveb85 the bearer token is Azure's automatic authorization method when accessing their REST APIs (at least all the ones I've worked with). I had no need for something extra at that time.

@steveb85
Copy link

for anyone else on this struggle, check carefully that your Params tab has nothing in it, even when not ticked, it becomes part of the canonicalResourceParts, thus throws the signature off.

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