This repository has been archived by the owner. It is now read-only.

Cannot upload to Azure due to improper Url construction #1949

Open
dapug opened this Issue Nov 18, 2017 · 6 comments

Comments

Projects
None yet
3 participants
@dapug
Copy link
Contributor

dapug commented Nov 18, 2017

Type of issue

  • Bug report

Uploader type

  • Azure
Fine-Uploader is prefixing the host site url to the Azure PUT request

Fine Uploader version

5.13.0

Browsers where the bug is reproducible

"Firefox" and "IE11" (and n/a)

Operating systems where the bug is reproducible

Windows 10

Exact steps required to reproduce the issue

For example:

  1. Set up site for Azure upload according to the docs
  2. In my case, my site is http://localhost:50021
  3. Launch Fiddler or some other wire monitoring app
  4. Upload a file
  5. See 404 error in IE or Chrome or Firefox debugger
  6. See 404 error in Fiddler

All relevant Fine Uploader-related code that you have written

` <script>
// Some options to pass to the uploader are discussed on the next page
var uploader = new qq.azure.FineUploader({
element: document.getElementById("uploader"),
request: {
endpoint: 'https://xxxx.blob.core.windows.net/user-content'
},
signature: {
endpoint: '/profile/uploadsignature'
},
uploadSuccess: {
endpoint: '/profile/uploadsuccess'
},
retry: {
enableAuto: true
},
deleteFile: {
enabled: true
}

    })
</script>`

Detailed explanation of the problem

Check this out, this is the RAW request captured in Fiddler:
PUT http://localhost:50021/%22https://xxxx.blob.core.windows.net/user-content/bd740824-3091-49f3-9448-6e6c1ece9d84.png?sv=2016-05-31&sr=b&sig=kOJhfV45%2Bk11Ov20vZChr7OvHKbYe%2Bk%2BJFe4SVVqRNA%3D&se=2017-11-18T02%3A14%3A29Z&sp=w%22 HTTP/1.1

See anything wrong here? PUT should NOT be going to http://localhost:50021 at all! And you can also see that Fine-Uploader concatenated it with the proper Url wrapped in encoded double quotes (%22)

My signature code is the same as your C# server example, and I can confirm it returns the proper sas Url (https://xxxx.blob.core.windows.net/... ) WITHOUT being prefixed with the root of my site (http://localhost:50021). My site is ASP.NET MVC Core 2.0 (irrelevant, but interesting).

The issue appears to be within Fine-Upload js code somewhere, wherever it is appending things and ultimately making the request to Azure.

@rnicholus

This comment has been minimized.

Copy link
Member

rnicholus commented Nov 18, 2017

I don't have time to look into this, but if you do find the cause for your issue, and if the issue is indeed caused by Fine Uploader, please do open up a PR with the fix.

@dapug

This comment has been minimized.

Copy link
Contributor

dapug commented Nov 18, 2017

RESOLVED.

The issue isn't technically due to Fine Uploader, but Fine Uploader could be tweaked to handle this discrepancy.

ASP.NET MVC will treat string responses as JSON, and therefore will wrap "quotes" around output, and add the Content-Type "application/json" for you automagically. By adding a "Produces" attribute to the controller, it forces the Content-Type you want:

[HttpGet]
[Produces("text/plain")]
public string UploadSignature(string _method, string bloburi, string qqtimestamp)
{
}

Yay! So yeah, File Uploader could be enhanced to trim junk like that, but it's really not the responsibility of the library IMO.

@rnicholus Just FYI, the docs are out of sync with the latest code on that parameter I highlighted above. it's _bloburi in the docs, but bloburi in the runtime code, and this can cause a brief head scratcher (null param) if you use the docs as you build your projects.

@rnicholus

This comment has been minimized.

Copy link
Member

rnicholus commented Nov 18, 2017

This is an instance where I would really appreciate a PR to fix this docs issue. Thanks for the report.

@dapug

This comment has been minimized.

Copy link
Contributor

dapug commented Nov 18, 2017

Honestly, I'm thinking about doing an entire .NET article. It was waaaay too much pain to put a simple thing together due to gotchas you just don't think about every day, and I was shocked to see no real ASP.Net examples out there. But yes, I will see what I can do about a PR for that at the very least.

@rnicholus

This comment has been minimized.

Copy link
Member

rnicholus commented Nov 18, 2017

A .NET article would be awesome. Were I a .NET developer, I’m sure I would have created a server side example, but alas I am not. So contributions welcome/encouraged.

@Martinsos

This comment has been minimized.

Copy link
Contributor

Martinsos commented May 30, 2018

Just in case somebody else is searching, I had the same problem. In my case it was mistake I made in SAS signer in my nodejs server: I was returning SAS token instead of SAS Uri. Also I can confirm that returning it as text/html works fine.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.