Question
· Jan 19, 2018

Upload client files using javascript/csp options

Hi I currently have a requirement to upload microsoft documents from a client's PC to a cache database, at present the idea is to use javascript to open the file and convert it to a binary stream and then for cache csp to upload the binary stream to the database.  Just wondered if anyone else had attempted this or are there better options !

Regards

Gary

Discussion (10)2
Log in or sign up to continue

In the web world, you don't have access to files on the client's machine, only if a user will give you this particular file. So, if a user manually downloaded your file, changed it. He should interact with your application again, to select and upload it back.

But, there is another way, how to achieve what you want. If I understood you correctly, you need a way to edit MSWord files stored in your application. In this case, instead of the download file, edit and upload back, we have now two ways.

  • WebDAV: it is an extension for HTTP for editing files through the network. You can make a special link which will be opened by MS Word, and after save, it will save this file back to the server, without storing it locally.
  • Office Online: it is almost the same office but which is working online installed on company`s server. It obviously has less functionality than the desktop version, but in most cases, it could be enough. And if online version does not support something in your file it will offer to open it through WebDAV, if you as a developer support it. As an example how it works, you can go to OneDrive, upload some office file, and edit it right there. Almost the same version available to install on your server.

In my previous company, I realized both ways, it was quite tricky but it still works.

Hi Eduard

I've been trying out your WebDAV implementation which I believe would be a really good fit for what we want. Thank you for putting that on GitHub!

What version of Cache does it require to work? We currently only have 2014.1.5 on our development box and I realised quite quickly that it must have been developed using a later version as the WebDav.AbstractREST class calls a method in OnHandleOptionsRequest that we don't have. Also you have an OnPreDispatch method in there which isn't a standard method in our %CSP.REST class, so I've ended up doing s sc=..OnPreDispatch(href,method,.continue) at the start of the various METHOD sections in the WebDav.REST class.

Also I was getting a error with your Route url statements initially. I was getting <REGULAR EXPRESSION> 27 %OnNew+3^%Regex.Matcher.1

so I had to change them

<Route Url="/:docname" Method="GET" Call="GET"/>
<Route Url="/:subdir1/:docname" Method="GET" Call="GET"/>
<Route Url="/:subdir1/:subdir2/:docname" Method="GET" Call="GET"/>

and that worked. In the zDispatchMap code in the .int routine it was ending up with Quit $ListBuild("","GET","GET"). I don't know if that is just another symptom of our version.

Our development box is Windows with it's own IIS

I can now at least get a document to come up when referencing it with ms-word:ofe|u|http://ipaddress:port/namespace/webdav/1.docx but it comes up as read-only. Do you have any advice why that might be. Is it our version of Cache?

I notice in the readme that it says to create a / web application. Did you literally mean "/"? If so presumably that would prevent the server from being used by anything else other than as a WebDAV server since all service requests would get diverted to the service? Although I did actually try creating a / web application and for some reason it didn't work anyway. Could that be part of why the documents are opening in read-only mode?

thanks

Wendy

What version of Cache does it require to work?

If think it requires 2016.1 but 2016.2+ would be preferable.

I notice in the readme that it says to create a / web application. Did you literally mean "/"?

You can create non-root (/something) web application, that should not be an issue on windows clients iirc.

Read-only office documents

Are OPTIONS requests processed correctly? Check OnHandleOptionsRequest method - you'll need to write a method that processes all OPTION requests and returns relevant headers.

If the problem with read-only Word files persists, it can be fixed by one of the above:

Additionally I recommend:

  • Installing 2017.2 (anything 2016.2+) separately and checking that it does work
  • Installing Wireshark and capturing a sample exchange on 2014.1 and 2017.2
  • Compare these two sessions to understand what fails on 2014.1

Hi Eduard

I've got that working in our version. I hadn't realised that OPTIONS requests were supposed to be picked up by the OnHandleOptionsRequest method (makes sense really!) , so I made a route map for those.  Had to make a / one too for the OPTIONS, then added the Allow and Public Header values to that section and it's working now!

thanks very much for your help

Wendy

what you describe sounds pretty much like code management, versioning.
these tools depend on appropriate plugins to Word, EXCEL, Eclipse, ....
to trap the SAVE in the appropriate "editor"

BUT this always means to have a specific piece of code installed on your client if you expect some "automatic" upload.
This thing may upload/download your documents over HTTP, WebSockets or whatever.

browsers should NEVER be allowed to access your local machine without manual confirmation.

I don't think the suggestions do what we want.  Correct me if I'm wrong but I think they both require user interaction in selecting a file with a browse button.

We've written a class to open various file types with their native applications or just in a browser window.  If the file is a word type file it opens with word. If they then edit that document, we want them to be able to click something to send those changes back up to the server.

Obviously we know there a long-winded route of getting the user to save it locally, user navigates to an upload page, clicks a browse button, manually select the file saved, then clicking an upload button, but (if there's a way ) we'd like them to click a button after they've finished editing which will save the file contents back to the original file on the server. 

Wendy