Two webclient uploads, 2nd one fails

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
ScottM
Posts: 38
Joined: Wed Mar 27, 2019 7:04 am

Two webclient uploads, 2nd one fails

Postby ScottM » Wed May 29, 2019 11:29 am

Well, after my little happy-dance on getting uploads working, I ran into a problem that I hope is simple.

I'm uploading a csv file to an Azure function, which in turn puts the e.base64EncodedContent into an Azure blob and returns the URI.

I want to put that URI into a class, convert that class to JSON (working) and upload the JSON into a different Azure blob container. It doesn't upload. To be clear, the first csv file uploads, but not the subsequent JSON upload attempt.

I thought maybe I had a bug in my JSON upload Function (separate function, uses separate container), so I tried uploading the file as another supported file type (xls) Function (same container as the csv, different file extension) and again, only the first one (csv) made it.

So then I went with just two sequential csv uploads of the same file, using the exact same Function (the function creates a GUID as the filename for the blob, so it's not overwriting the same file twice, and in the first example, that was targeted at a different blob container) and I only get one uploaded csv file.

Code: Select all

mProspectOrder.sFileUri = await webClient.UploadStringTaskAsync("https://xyz.azurewebsites.net/api/UploadCsv", "POST", ms64BitEncodedFile);
mProspectOrder.sFileUri = await webClient.UploadStringTaskAsync("https://xyz.azurewebsites.net/api/UploadCsv", "POST", ms64BitEncodedFile);

where "xyz" is the actual App Service exposing the Azure Functions.

The first example (csv and json) I was using two different webclient instances. The latter, obviously, the same one.

Is there a problem on my end, or some other issue?

Side note: I have some xaml that, depending on the state of two radio buttons, collapses and hides two different stackpanels, depending on the radio button selections. In the simulator, this only works for one click of the radio buttons. Subsequent clicks do not. It works fine in the browser, but if this is something helpful to fix, I can provide the xaml.

ScottM
Posts: 38
Joined: Wed Mar 27, 2019 7:04 am

Re: Two webclient uploads, 2nd one fails

Postby ScottM » Wed May 29, 2019 2:30 pm

Update. I went back and tried two json uploads and the 2nd one failed.

Still messing.

ScottM
Posts: 38
Joined: Wed Mar 27, 2019 7:04 am

Re: Two webclient uploads, 2nd one fails

Postby ScottM » Wed May 29, 2019 5:16 pm

Weirdly, I always get the first one if I try two. And I get this error:

SEC7120: [CORS] The origin 'http://www.xyz.com' did not find 'http://www.xyz.com' in the Access-Control-Allow-Origin response header for cross-origin resource at 'https://abc.azurewebsites.net/api/UploadCsv'.

But I only get one of those, not two.

Does this make sense to anyone?

ScottM
Posts: 38
Joined: Wed Mar 27, 2019 7:04 am

Re: Two webclient uploads, 2nd one fails

Postby ScottM » Thu May 30, 2019 9:57 am

Update. I tried basically the same code (uploading two strings) in a WPF app, I got two files created. The code:

Code: Select all

string sJson = "A test";
WebClient webClient2 = new WebClient();
string sOrderUri = await webClient2.UploadStringTaskAsync("https://xyz.azurewebsites.net/api/UploadOrder", "POST", sJson);
sOrderUri = await webClient2.UploadStringTaskAsync("https://xyz.azurewebsites.net/api/UploadOrder", "POST", sJson);


and the results:

BlobFiles.png
BlobFiles.png (28.77 KiB) Viewed 22485 times


So unless I'm missing something, like somehow CORS on the app service is only killing the 2nd upload*, I think there might be a bug on the CSHTML5 side.

* I tested from the target website and added that domain to the CORS in the app service. I can't understand how CORS will only kill the 2nd attempt, but allow the first, yet I added it anyways.

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Two webclient uploads, 2nd one fails

Postby JS-Support @Userware » Wed Jun 12, 2019 1:08 am

Hi,

Could you please install Fiddler ( https://www.telerik.com/download/fiddler ) and inspect the outgoing messages? If you go to the "Inspector" tab and you click the "Raw" view, you can then compare the outgoing requests produced by CSHTML5 to those produced by WPF, and see what causes the issue. With Fiddler you can even modify a request, and then "Replay" the modified one, to see if the modified one works properly (to do so, right-click a request, click "Replay", and then click "Reissue and edit").

Another tip is to do step-by-step debugging on the "UploadStringTaskAsync" method in CSHTML5, which is not very long. To do so, you have two ways:
- Either use the browser developer tools (F12) and place a breakpoint in the "UploadStringTaskAsync" method of the file "cshtml5.js" (we recommend you to use the version 2.x of CSHTML5 because the JavaScript code is much cleaner)
- Or use the C# source code of CSHTML5 and do step-by-step debugging with the Simulator, by following the steps described in the paragraph "How to test the changes that I make to the source code?" at the following URL:
https://github.com/cshtml5/CSHTML5

ScottM wrote:Side note: I have some xaml that, depending on the state of two radio buttons, collapses and hides two different stackpanels, depending on the radio button selections. In the simulator, this only works for one click of the radio buttons. Subsequent clicks do not. It works fine in the browser, but if this is something helpful to fix, I can provide the xaml.

Yes, if you could please provide the code to reproduce this RadioButton issue we may be able to fix it in a future release.

Thanks
Regards

ScottM
Posts: 38
Joined: Wed Mar 27, 2019 7:04 am

Re: Two webclient uploads, 2nd one fails

Postby ScottM » Thu Jun 13, 2019 7:17 am

OK, I'll look into those debugging tips.

And I'll try and create a smaller project with the radio button visible/collapsed issue.

Thanks.

ScottM
Posts: 38
Joined: Wed Mar 27, 2019 7:04 am

Re: Two webclient uploads, 2nd one fails

Postby ScottM » Wed Jun 19, 2019 2:04 pm

OK, found it. The F12 was showing:

SEC7120: [CORS] The origin [X] did not find [X] in the Access-Control-Allow-Origin response header for cross-origin resource at [Y].

Where X was the website (in just http, not https) and Y was the Azure function.

I had X listed in the Azure function CORS, but not as an http, rather https. I'm not sure exactly how it got called as http, all references to it in my code are https.

So the code was crashing out on the CORS, and I did not see an exception in my code, though I had the call wrapped in a try/catch block. So I guess not all errors are caught, or do I need to do something special to see these sorts of exceptions in the try/catch?

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Two webclient uploads, 2nd one fails

Postby JS-Support @Userware » Wed Jun 19, 2019 11:57 pm

Thanks. I am glad the cause of the issue could be found.

So the code was crashing out on the CORS, and I did not see an exception in my code, though I had the call wrapped in a try/catch block. So I guess not all errors are caught, or do I need to do something special to see these sorts of exceptions in the try/catch?

We haven't found any way in JavaScript to catch the CORS-related exceptions. They seem to not be catchable. If you happen to find a way to do so in JavaScript, please let us know and we will reflect it in C#.

Regards

ScottM
Posts: 38
Joined: Wed Mar 27, 2019 7:04 am

Re: Two webclient uploads, 2nd one fails

Postby ScottM » Thu Jun 20, 2019 10:51 am

OK, at least I can get my expectations adjusted. I hadn't encountered too many situations where a try/catch didn't … catch.

On the visible/collapse issue, attached is a zip of the xaml and cs files that should allow you to duplicate the issue. The top set of radio buttons control what is displayed below (along with a removed file dialog). Clicking the top two radio buttons doesn't change the display at all in the simulator, but if you run it in the browser, it works reliably.

I could send the whole project, but I think these files should allow you to replicate it by replacing an empty project's files with these.
Attachments
CSHTML5V2Play.zip
(3.43 KiB) Downloaded 629 times

ScottM
Posts: 38
Joined: Wed Mar 27, 2019 7:04 am

Re: Two webclient uploads, 2nd one fails

Postby ScottM » Tue Jul 23, 2019 10:49 am

ScottM wrote:...

On the visible/collapse issue, attached is a zip of the xaml and cs files that should allow you to duplicate the issue. The top set of radio buttons control what is displayed below (along with a removed file dialog). Clicking the top two radio buttons doesn't change the display at all in the simulator, but if you run it in the browser, it works reliably.

I could send the whole project, but I think these files should allow you to replicate it by replacing an empty project's files with these.

I just wanted to bump the above post to see if you were able to replicate and/or fix the simulator radio button problem in the sample code I posted.

I was checking in to see if there might be a new 2.0 release that addressed it. Again, it works in the browser, so if I had to have a fail, I much prefer it in the simulator. :)

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Two webclient uploads, 2nd one fails

Postby JS-Support @Userware » Fri Aug 09, 2019 4:40 am

Thanks for sending the project to replicate the issue related to the radio buttons. It is on our backlog and one of our developers will work on it asap. I will keep you updated. Thanks a lot.

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Two webclient uploads, 2nd one fails

Postby JS-Support @Userware » Wed Aug 28, 2019 1:13 pm

Hi,

We have fixed the RadioButton issue. Please expect the fix to be available in the very next build.

Thanks
Regards


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 33 guests

 

 

cron