Welcome Guest Search | Active Topics | Sign In | Register

Asynchronous File Upload Options
Scott
Posted: Tuesday, June 30, 2020 2:28:16 PM
Rank: Newbie
Groups: Member

Joined: 6/24/2020
Posts: 7
I have a desktop application that needs to upload a file asynchronously to our website which is displayed in a form using EO.WebBrowser. I have the local file path of the file to be uploaded. The online process is behind the scenes with a specific file targeted on the website. How do I do this? Thanks in advance.[code=cs]

Also I need to recover Header items on return.
What I have tried:

EO.WebBrowser.Request request = new EO.WebBrowser.Request(serverurl);

request.Headers.Add("Content-Type", @"application/pdf");
request.Headers.Add("Filename", FilePath.FileName);
request.Headers.Add("userID", userID);
request.Headers.Add("mime_type", @"application/pdf");
request.Method = "POST";

string response = webView1.LoadRequest(request).ToString();
eo_support
Posted: Wednesday, July 1, 2020 7:19:43 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

Posting a file is much more complicated than you think. You need to format the request data exactly as it should be and you can't just pull things out of your head and hope it would work. So the first step is to search online to see how the request data should be formatted.

The next step for you is to determine whether you need to do that with EO.WebBrowser or not. You do not need to use EO.WebBrowser to upload a file. EO.WebBrowser is mainly for you to load and run a web page. If you just want to send a file to the server, you can just use .NET's built in WebRequest class.

When you send a request to the server, you will get a response. EO.WebBrowser becomes useful when it comes to the response. For example, if you were to upload a picture and the server sends back a response that contains complex UI that allows you to preview/edit the picture (such as ShutterFly), then in order to present that complex UI to the end user you will need EO.WebBrowser. On the other hand, if you are just interested in a HTTP result code (or some other kind of structural data result such as XML) to indicate whether the upload is successful or not, then you can get those information directly through .NET's built-in support.

If you indeed need to use EO.WebBrowser, you need to follow the steps here to format the request data:

https://www.essentialobjects.com/doc/eo.webbrowser.postdataitemconstructor1.aspx

Hope this points you to the right direction.

Thanks!
Scott
Posted: Wednesday, July 1, 2020 6:19:50 PM
Rank: Newbie
Groups: Member

Joined: 6/24/2020
Posts: 7
Thank you for the information. I now realize that although I am not using a native .net browser, all the other .net functionality is available. So I pulled the WebClient out of my head. It works getting the CaptureOnTough plugin file up to the site.

WebClient client = new WebClient();

string xxxxID = webView1.EvalScript("document.getElementById('xxxID').value").ToString();

string serverurl = QboPluginSettings.GetServerlUrl() + @"xxxxxx/";
client.Headers.Add("Content-Type", @"application/pdf");
client.Headers.Add("XXXname", XXXXXXX);
client.Headers.Add("xxxid", xxxxID);
client.Headers.Add("mime_type", @"application/pdf");

Logger.LogDebug("Server URL: " + serverurl, this.GetType());

Array response = client.UploadFile(serverurl, "Post", StrFilePath);
WebHeaderCollection resp = client.ResponseHeaders;
for (int i = 0; i < resp.Count; i++)
Logger.LogDebug("Response: " + i + " " + resp.GetKey(i) + " - " + resp.Get(i), this.GetType());


Thanks again! Have a good one.

Scott
eo_support
Posted: Saturday, July 4, 2020 1:53:40 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Great. Glad that you got it working!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.