LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Send a file to the client in response to HTTP Request in Web Services

Highlighted

Hi all,

 

Is it possible in LabVIEW web services to transmit a binary file to the client (to be downloaded) in response to a HTTP Request? For example map a URL as /download/filename to download the file to local computer?

 

Thanks

0 Kudos
Message 1 of 6
(3,302 Views)
Highlighted

 

If you are programmatically creating the data in LabVIEW then the LabVIEW Web Development Community has an example that lets you See an Image of the Front Panel on the Web using LabVIEW Web Services which may be helpful for you.

 

Here are the key things to point out:

  1. The Web Service VI is configured for a Stream response
  2. Set HTTP Response MIME Type VI and Write Response VI are used
  3. The MIME Type used in that example was 'image/png'. If it is just a blob of arbitrary binary data then you can use the MIME Type 'application/octet-stream', but if you can use a MIME Type the browser understands like 'application/pdf', 'audio/mpeg', 'application/zip', etc then it can handle it better.

Alternatively, if the file is just a static file saved on disk and you want to be able to share it there is a help topic that describes Integrating Static Content into a Web Service.


Milan
0 Kudos
Message 2 of 6
(3,273 Views)
Highlighted

Thanks Milan for your response. I am trying to get a filename from the client, and then send an AVI file with that name that is stored on the server PC to the client. I've followed your suggestion, and the code is like this:

  DLVideos.PNG

 

The VI is also set as RESTful Web Method VI with stream output, using headers and buffered. When I send a request through client, it creates a file with the right filename in the download folder but the file size is zero. What am I doing wrong? By the way, I cannot statically refer to the file, because these files are programetically created and managed.

 

Thanks,

 

Soheyl

0 Kudos
Message 3 of 6
(3,242 Views)
Highlighted

Hi Sohey,

I am looking into this use case closer. To make sure I understand what is going wrong, you are saying that you are trying to be able to post a file name from the Client, have the Server read that file name, find the file on the Server, and then send it to the Client? And as of it's current state, it seems to work in the sense that a file is being created on the Client under "downloads" but that there is no data in that file?

 

Also, how large of files are you trying to send to the Client? Also have you looked into using a TCP connection to send the file?

 

Alex W.

Applications Engineer | National Instruments

Alex W.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 6
(3,218 Views)
Highlighted

Hi Alex,

 

That's right. The files are going to be around ~5 MB. I will not have any program installed on the client machine, except the normal windows programs, i.e. I'll have the web browser, but cannot make a new program in LabVIEW and install it on the client. Not sure how I can do this with TCP connection.

 

Soheyl

0 Kudos
Message 5 of 6
(3,211 Views)
Highlighted

1) Are you getting any errors in the Webservice VI? 

 

You can set a breakpoint in the VI, run the webservice as debug, hit the page from the browser, and step through each VI to see if errors occur on the wire.

 

2) Do you see the same behavior in multiple web browsers?

 

3) The Write Response VI says to use the Flush Output VI in the documentation. You may need to add that.

 

4) Try the more generic MIME Type 'application/octet-stream'

 

5) I vaguely remember having issues in some cases using the Set HTTP Response MIME Type VI with streaming output. If the above is not helping try replacing the Set HTTP Response MIME Type VI with the Set HTTP Header VI with the header input 'Content-Type' and header value to the MIME Type


Milan
0 Kudos
Message 6 of 6
(3,207 Views)