0

I need help with sending a file from a browser to another device that is connected to a machine that is running a server. I'm new to web application programming as well as back-end programming.

The existing code can move a file that exists on the server to the device by calling the web API as follows - http://localhost:3333/api/Install_Job_to_device/filename.zip..

The existing server-side code is also capable of receiving a file from the browser.

Now I want the browser code to call the API http://localhost:3333/api/Install_Job_to_device/filename.zip once the filename.zip file is uploaded to the server, so that it gets transferred to the device.

The current code which uploads file to the server is below. Can you please suggest how to make the Web API call from here ?

<h3>File Upload:</h3>
Select a file to upload: <br />
<form action="../api/RdaServer" method="post"
                        enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
</form>

1 Answer 1

1

Looks like you are almost done.

If both of the code (uploading to server and push to device works), you can consider the following options:

Option 1: (Making changes to your upload API)

Make changes to your upload webAPI such that it calls the corresponding webAPI (http://localhost:3333/api/Install_Job_to_device/filename.zip..) to push the file to the device instead of modifying your web request in the html you provided.

Option 2: (Making two web requests)

You have make slight changes to your upload webAPI to return an acknowledgement when the file upload is successful. From there, you create another web request and call your pushing webAPI to deliver the file to your device.

Have fun programming! Cheers!

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Sihao. I want to try option 2, but that is what I haven't been able to figure out. I'm new to Angular or Javascript to make it work. Was looking out here for suggestions.
@SharatChandra I am not well-versed with angular, but with javascript, you can try using AJAX calls to submit your request. When doing so, you can change your upload webAPI logic to return true/false depending if the upload was successful. In the AJAX callback, you check the results of the upload. If it is successful, you call the push webAPI through another request. Otherwise, throw an error to the user. Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.