File Upload

  • Thread starter Thread starter Neo
  • Start date Start date
N

Neo

Hello,

I am receiving a file as a binary stream from a C++ Client Application.
From the application, the file is being sent as a
"Multipart/form-data".

I want to receive this file on the server, for which i am using
Request.Inputstream and reading it into a byte array. This is not
working as it is coupling the binary content with some Boundary and
text such as "Content-Disposition:
form-data; name="upload_file"; filename="C:\dustbin\test.bin"
Content-Type: "application/octet-stream"

Is there any way in ASP.NET by which i can read a File being sent from
an Application (not a HtmlInputFileControl), can be read, without the
unnecessary data/ or any way in which i can filter the binary data.

Please help, i am stuck big time on this. This feature is imperative
for the project :(

Requesting help.

Regards

Sunil Jambekar
 
Hi Neo,

You can try

System.Web.HttpPostedFile file = Request.Files[0]; // suppose there is only
one file
//or
System.Web.HttpPostedFile file = Request.Files["file_name"];


On client-side you can use

System.Net.WebClient client = new WebClient();
byte[] data = client.UploadFile(url,"POST",fileName);

To send file to server.



HTH

Elton Wang
(e-mail address removed)
 
hi elton,

the client is in C++

The details are as follows. There is a desktop application in MFC, and
i am building a web interface for that application in ASP.NET. I have
to upload a file from the C++ Application to ASP.NET web application.

I am using Multipart/form-data to transfer the file, as sending it as a
HTTP request in synchronous mode hangs my C++ application. What is
happening is that i am receiving the file on the server which i am
storing to the disk using request.inputstream.

What happens is that the boundary and the Content-Disposition :
application/octet-stream comes in the binary inputstream which i am
trying to filter. What i did was that i saved the file on the server
and then read it line by line using streamreader and streamwriter, but
it gives me some encoding problem.

So i am looking at ... can a file be uploaded from C++ Desktop
application to a ASP.NET web server application without the junk
content in the stream, i.e. only the file (complete as it was sent), or
is there any way to parse binary data??

All help is appreciated ... thanks for the same.

Regards

Sunil

Elton said:
Hi Neo,

You can try

System.Web.HttpPostedFile file = Request.Files[0]; // suppose there is only
one file
//or
System.Web.HttpPostedFile file = Request.Files["file_name"];


On client-side you can use

System.Net.WebClient client = new WebClient();
byte[] data = client.UploadFile(url,"POST",fileName);

To send file to server.



HTH

Elton Wang
(e-mail address removed)




Neo said:
Hello,

I am receiving a file as a binary stream from a C++ Client Application.
"Multipart/form-data".

I want to receive this file on the server, for which i am using
Request.Inputstream and reading it into a byte array. This is not
working as it is coupling the binary content with some Boundary and
text such as "Content-Disposition:
form-data; name="upload_file"; filename="C:\dustbin\test.bin"
Content-Type: "application/octet-stream"

Is there any way in ASP.NET by which i can read a File being sent from
an Application (not a HtmlInputFileControl), can be read, without the
unnecessary data/ or any way in which i can filter the binary data.

Please help, i am stuck big time on this. This feature is imperative
for the project :(

Requesting help.

Regards

Sunil Jambekar
 
Hi Sunil,

I’m not very familiar with C++. However, you can think about to build a
small .NET application to upload file. That will be easy for processing the
file on server-side. And it is not difficult to call the .NET program from
your C++ application.

Or you can make .NET component to perform upload file function, then call
the .NET component from COM
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/cominterop.asp).

HTH

Elton


Neo said:
hi elton,

the client is in C++

The details are as follows. There is a desktop application in MFC, and
i am building a web interface for that application in ASP.NET. I have
to upload a file from the C++ Application to ASP.NET web application.

I am using Multipart/form-data to transfer the file, as sending it as a
HTTP request in synchronous mode hangs my C++ application. What is
happening is that i am receiving the file on the server which i am
storing to the disk using request.inputstream.

What happens is that the boundary and the Content-Disposition :
application/octet-stream comes in the binary inputstream which i am
trying to filter. What i did was that i saved the file on the server
and then read it line by line using streamreader and streamwriter, but
it gives me some encoding problem.

So i am looking at ... can a file be uploaded from C++ Desktop
application to a ASP.NET web server application without the junk
content in the stream, i.e. only the file (complete as it was sent), or
is there any way to parse binary data??

All help is appreciated ... thanks for the same.

Regards

Sunil

Elton said:
Hi Neo,

You can try

System.Web.HttpPostedFile file = Request.Files[0]; // suppose there is only
one file
//or
System.Web.HttpPostedFile file = Request.Files["file_name"];


On client-side you can use

System.Net.WebClient client = new WebClient();
byte[] data = client.UploadFile(url,"POST",fileName);

To send file to server.



HTH

Elton Wang
(e-mail address removed)




Neo said:
Hello,

I am receiving a file as a binary stream from a C++ Client Application.
From the application, the file is being sent as a
"Multipart/form-data".

I want to receive this file on the server, for which i am using
Request.Inputstream and reading it into a byte array. This is not
working as it is coupling the binary content with some Boundary and
text such as "Content-Disposition:
form-data; name="upload_file"; filename="C:\dustbin\test.bin"
Content-Type: "application/octet-stream"

Is there any way in ASP.NET by which i can read a File being sent from
an Application (not a HtmlInputFileControl), can be read, without the
unnecessary data/ or any way in which i can filter the binary data.

Please help, i am stuck big time on this. This feature is imperative
for the project :(

Requesting help.

Regards

Sunil Jambekar
 
Looks like your application using the same RFC standard than the input
type=file control. If yes, there is no difference and you'll be still able
to use System.Web.HttpContext.Current.Request.Files to have posted files
decoded for you...
 
Hello All,

My problem got solved by changing some C++ Code and using
Request.Files.Get(0)

Cheers

Sunil Jambekar
 
Back
Top