Upload with no GUI??

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Upload with no GUI??

Guest-6
Hello, I am trying to modify your code so that I can use a Windows Form to submit the file for download?  I have tried so many other .net complient components that I am not even sure that this is possible.. However since this is Open Source (thankyou(x)3)  I was wondering if I could modify the InputFile object.  I was thinking of (since I know which file I want from the Contex.Request.File  collection within the Control_Load method) I would just hard code it for the time being for testing purposes.  I appologize in advance because I am very green to this tecnology. 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload with no GUI??

Dean Brettle
Administrator
Hi,

I'm afraid I really don't understand what you are trying to do.  To help, I need you to describe what you are trying to accomplish and what you want the user experience to be.  For example, you might say "When a user clicks a button in my desktop app, a specific hard-coded file is uploaded to my server.  No file selection is displayed, but a progress bar is displayed during the upload."  If that's what you are looking for, please says so, otherwise please try describing the desired user experience in similar terms.

Thanks,

--Dean

 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload with no GUI??

Guest-6

Hello again,

 

Sorry for the confusion. But it seems that you did in-fact grasp the core of what I am trying for the user to experience.  I would like to know if there is a way for the user to press a button on the desktop, and send a file to my server.  I would not like for there to be any popup’s for html progress, I would like for the progress to be sent back in a response that i will listen for, and I will then create a desktop progress meter/metrics display?  

 

I appreciate your considerable efforts within this area of CS, and again I apologize for not being specific enough. 

 

--ron

 

 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload with no GUI??

Dean Brettle
Administrator
[3/4/2006 Updated for NeatUpload-trunk.240 (and later) and NeatUpload-1.2]
Thanks for the clarification.  NeatUpload could help you achieve what you want, but it is only part of the solution.  Here's how I'd go about it if I were you:

Use NeatUpload-1.2.x if it has been released.  Otherwise, use NeatUpload-trunk.240.zip or later. 

On the client side, when the user clicks the button, the first thing you need to do is generate what I call a postBackID.  This is just an globally unique identifier (GUID).  I use a hex-encoded 128-bit (16 byte) cryptographically secure random number for the GUID in NeatUpload's FormContext constructor (FormContext is used by InputFile).  You could do the same or use something else.  Next, create a new Thread to send the file to the server.  On that thread, use an HttpWebRequest to send a "multipart/form-data" request (using the POST method) to an URL of the form "http://yourserver/path/to/YourUploadPage.aspx?NeatUpload_PostBackID=postBackID" page, where YourUploadPage.aspx contains a NeatUpload InputFile control.  The request would contain the file you want to upload and, in the "Content-Disposition" header for that part of the request, would contain the attribute-value pair "filename=nameOfFile".  It would also contain a "name" attribute, whose value would match the ID of the InputFile control.  The codebehind for the aspx page would process the uploaded file however you choose (eg move it to a permanent location).  NOTE: You might be able to do the upload using WebClient.UploadValues() instead, but I don't know whether that will generate a "multipart/form-data" request, which is what NeatUpload needs.  If WebClient.UploadValues() works, using it would save you the trouble of formatting the request by hand.

While the upload is occuring in the new thread, your original thread would poll the server for progress information.  I would do that by polling a custom Progress.aspx page that returns the progress info you want in an XML document.  You'd parse the XML doc to get the progress info.

See the "Uploading from a Client Application" section of docs\Manual.html included in the release for more details.

As you can see, if you're new to .NET, you are going to need to learn about threading, making web requests from a client, and creating and using web services.  You are also going to need to learn about the format of "multipart/form-data" http requests.  However, once you have that knowledge, the actual number of lines of code you need to write shouldn't be particularly high (maybe a few hundred?). 

If you are interested in paying me to implement what I've described above, just send me an email (dean at brettle dot com).  If not, I hope the above helps you get started and I wish you the best of luck in your endeavor.

Cheers,

--Dean
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload with no GUI??

Guest-6

Dean,

 

You are a genius!!  My good fortune find you where ever you may be!! Thank you for both the time it took out of your schedule, and for your speedy response.  I’ll get right to work and tell you of the results in a few days :)

 

Ron

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload with no GUI??

Guest-6

Dean,

First of all, a thousand thanks for writing NeatUpload!  You are about to save my life (well, maybe just my sanity and some money).  I’m also trying to use NeatUpload from a non-browser application.  I have most everything working, but have run into a snag that I can’t seem to figure out. 

 

 

The issue is that inputFile seems to be null when it shouldn’t be.  I know the file makes it to the temporary directory, but that’s as far as I get.  I’m developing on Windows with IIS 6.  The client application I’m using uses a 3rd party component (Xupload) to do the http (https actually) post.  I had to make a few changes in your code to accommodate Xupload since I can’t change what it sends.  Xupload sends FILE001 for the name attribute and I don’t have a way to change it.  So I send the postbackID as a querystring and then set fileID with the appropriate data in FilteringWorkerRequest.ParseOrThrow() if fileID starts with “FILE”.

 

 

I also had to remove checks for IsPostBack since the client application does a post and not a PostBack.

 

 

At this point, I’m not even trying to use the progress (Xupload has client side progress), although I would eventually like to use the progress server side to get a status on incoming files.

 

 

I hope I gave you enough details.

 

 

Is there something obvious that I missed?  Any help would be appreciated.

 

 

Thanks again,

 

 

Onnig

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload with no GUI??

Dean Brettle
Administrator
I suspect that you are setting the fileID incorrectly before calling CreateUploadedFile().  Please use a debugger or some logging to determine what value is being passed to CreateUploadedFile() for the fileID, and let me know what that value is.  Also, please include the few lines of FilteringWorkerRequest.cs that you changed and the InputFile tag from you aspx.  Hopefully, those bits of info will be sufficient for me to diagnose the problem and suggest a fix.

BTW, you said that inputFile is null, but you meant that inputFile.TmpFile is null, right?

--Dean
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload with no GUI??

Onnig Kouyoumdjian
Dean,
 
This is from the log:
DecoratedWorkerRequest.ProcessRequest(\decoratedworkerrequest.cs:77) Calling HttpRuntime.ProcessRequest()
FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:337) contentTypeHeader=multipart/form-data; boundary=---------------------------nXvAplNuymtSe
FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:338) Parsing content length
FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:342) =513
FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:345) boundary=-----------------------------nXvAplNuymtSe
FilteringWorkerRequest.FindBoundary(\filteringworkerrequest.cs:172) grandTotalBytesRead=513
FilteringWorkerRequest.FindBoundary(\filteringworkerrequest.cs:173) Found boundary
FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:375) header=Content-Disposition: form-data; name="FILE001"; filename="f:\x\ForeverStor\Backup\5c7a50944790a093b57e9bb78c2f9576.fes"
FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:375) header=Content-Type: application/octet-stream
FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:375) header=X-File-Date: Sun Oct 12 04:13:00 2005
FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:375) header=
2005-10-11 22:13:06,251 [3508] [DEBUG] Brettle.Web.NeatUpload.FilteringWorkerRequest Brettle.Web.NeatUpload.FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:398) fileID = NeatUpload_378540001dfa4855abe5a57b99b6b5c1-inputFile
FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:399) fileName = f:\x\ForeverStor\Backup\5c7a50944790a093b57e9bb78c2f9576.fes
FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:402) Calling UploadContext.Current.CreateUploadedFile(NeatUpload_378540001dfa4855abe5a57b99b6b5c1-inputFile...)
UploadContext.CreateUploadedFile(\uploadcontext.cs:93) In CreateUploadedFile() controlUniqueID=inputFile
UploadContext.CreateUploadedFile(\uploadcontext.cs:101) Storing UploadContext in Application[NeatUpload_378540001dfa4855abe5a57b99b6b5c1]
FilteringWorkerRequest.FindBoundary(\filteringworkerrequest.cs:172) grandTotalBytesRead=513
FilteringWorkerRequest.FindBoundary(\filteringworkerrequest.cs:173) Found boundary
FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:398) fileID =
FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:399) fileName =
FilteringWorkerRequest.ParseOrThrow(\filteringworkerrequest.cs:411) Done parsing.
 
In DecoratedWorkerRequest.cs, I added:
 
public string TID
            {
                  get { return OrigWorker.GetQueryString(); }
            }
 
In FilteringWorkerRequest.cs:
 
if (String.Compare(headerName, "Content-Disposition", true) == 0)
      {
            fileID = GetAttribute(header, "name");
            fileName = GetAttribute(header, "filename");
           
            if (fileID.StartsWith("FILE"))
            {
                  fileID = "NeatUpload_" + base.TID.Replace("TID=","") + "-inputFile";
            }
      }
 
InpupFile.cs if (this.Page.IsPostBack) is commented out
 
I did mean inputFile is null, when I check if (inputFile.TmpFile != null) I get: “System.NullReferenceException: Object reference not set to an instance of an object”
Unfortunately, debugging with breakpoints doesn’t seem to work with this (at least in VS.NET), so I have to rely on logging only.
Onnig
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload with no GUI??

Onnig Kouyoumdjian
Dean,
 
I figured out the problem. I knew I was doing something stupid. I did not have the control on the aspx page.
 
Onnig
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload with no GUI??

Dean Brettle
Administrator
Glad to hear you got it working!

--Dean
Loading...