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: 32
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: 32
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: 32
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: 32
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 103 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: 1023
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: 32
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.


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 3 guests

 

 

cron