But in my case, I really need sending all files together. The problem is not
performance, but is the logic of server side. The function of the app isn't
just store files in server machine. indeed it removes all files after the
method execution. the application process all files that were sent, do what
it have to do and erase all uploads. Sending one by one, I would store them
into a folder on server and after all uploads, that are made in assync way,
I call other method that get those files on disk and do what I have to do.
it means rewrite too much code written to work on server side, work a lot in
assync problems that could happen, and perhaps in the end, it won't be so
elegant.

2009/4/24 Eduard Martini <[email protected]>

>
> I have no idea how to "trick" the security to auto complete the file
> input element with a path. Why mot let the user simply choose the file
> (s)? Then all is simple.
>
> on step 8 I do:
>
> #initialize the request
> request.open('POST', my_site/my_action?
> from_offline=true&size=size&type=type&whatever_other_param_I_need);
> #set the callback of the request (this code will be executed at every
> statechange, after request is sent
>     request.onreadystatechange = function() {
>            if (request.readyState == 4) {
>                eval(request.responseText);
>            }
>        };
> #send the request with the content of file (blob is store.getAsBlob
> from step 7)
>        request.send(blob);
>
> My backend is a rails application. In RoR, when a form with an input
> type file comes, the object resulted from params[:file] is of class
> ActionController::UploadedFile.  and have several methods defined
> (read, original_filename,size, content_type).
>  Because the further processing of those files is made with lots of
> code that is already written and at the time when was written was
> assumed in may places that the only way how a file can get there is
> from an input type file, sending an object of another type was not an
> option. Also I was to lazy to write a complete different code for
> processing images that came from offline mode, so the simple solution
> was something like that:
>
> if this_file_is_from_offline
>  create_an_uploadedFile object from the content of file, size,
> content_type and name (I know all those and I send them as params from
> offline)
> end
> normal app code same for online and offline uploads
>
> About sending more files in a single request, I see no reason to do
> that. requests made by httpRequest class are all asynchronous. If I
> would start uploading 100 files in 1 request, will put one by one, if
> I start 100 requests with a file, 100 files will be uploaded in same
> time without blocking anything (I am still syncing db and other
> resources in same time).
>
> To send your input text field, put it on the url as a get param. If
> you have a more complex structure, can make an ajax request with file
> references and a httpRequest with the content of file and join those
> infos on server side.
>
>
> On Apr 24, 12:14 pm, frog <[email protected]> wrote:
> > hello,
> > I'm interested too by how to do an automatic file upload from the
> > local store.
> > I didn't want to use deprecated method, and I didn't think to re-write
> > it. Eduard, Could you post your re-written code here plz?
> > I managed to do it using an other method which works only on firefox
> > for the moment:
> > I needed to fill an input file form with a javascript code (which is
> > normally impossible for security reason) in order to send it to the
> > server while synchronizing.
> > I managed to do it using a signed javascript and command from XUL,
> > something like this:
> >
> > function fillInputFile(filepath){
> >         try {
> >                 netscape.security.PrivilegeManager.enablePrivilege
> > ("UniversalXPConnect");
> >         }
> >         catch(e){
> >                 alert("Permission to read file was denied.");
> >                 window.open("http://localhost/uploadFile/myca.crt";);
> >                 return;
> >         }
> >
> >         var fileIn = document.getElementById("myfile");
> >
> >         var aFile = Components.classes["@mozilla.org/file/local;1"]
> >                 .createInstance(Components.interfaces.nsILocalFile);
> >         aFile.initWithPath(filepath);
> >         if (aFile.exists()) {
> >                  alert("dataObj filename is " + aFile.path);
> >                  fileIn.value = aFile.path;
> >         }
> >
> > }
> >
> > But I had several problems:
> > - how to sign my js? I created my own CA, so if it's the first time
> > the user come on my page I ask him to install my CA : window.open
> > ("http://localhost/uploadFile/myca.crt";);
> > -next problem: the filepath: because I need the local path to my file.
> > I used a signed java applet which can go on the local store directory.
> >
> > I know my method is complicated that's why I ask you your code.
> > And finally an other question Eduard, what file path will you give for
> > the input file form?
> > thanks for your help, I really need a good cross-platform method to do
> > it, because for the moment it just works on firefox...
>

Reply via email to