Question

In my ASP.NET application, I want to make a POST request out to a third-party, document editing service (Zoho). I understand how to make this request with a front-end form, and how to make one in my VB.NET code-behind. However, since I the file I'm sending is stored in my database as a byte array and the POST results (an editor page on the Zoho website) must be displayed in a special 'target' (new window or an iframe), it looks like I need some weird combination of both.

Basically, I want to attach the content of this byte array

Dim fileContents() As Byte = Files.get(fileId)

to the file input field in this form

<form id="theForm" action="http://zohoservice" method="POST" target="_blank" >
    ...
    <input type="file" name="fileContents" />
</form>

and then submit it via javascript like this

theForm.submit();

I hope I'm not asking for the impossible. Thanks for your help!

Was it helpful?

Solution

You actually can't do what you're suggesting. When using an <input type="file" .../> the uploaded file is never loaded into the HTML. Instead it's included as part of the POST request. So what you want to actually do is craft a complete POST request, and submit that post to your action (http://zohoservice).

This is doable, but it's going to be a bit of work on your end, and you'll need to understand how to create a MIME multipart POST request. And if there are any anti-botting technologies or view state tracking (kinds of things) then you'll run into some trouble there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top