Share file API - Add file for quick share
OVERVIEW
Purpose
This api method is used for uploading a file to a shared location. This method is different to "Add file" method in that the location to which the file is uploaded is not visible in the web based interface or accessible through the "Add file" API method. These files are considered temporary files and their existence depends on the share in which these files are used. The shared file is removed if there is no share referencing the file or all shares referencing the file have expired.
Request URL
POST /shares/content
Parameters
Parameter Name | Type | Description |
---|---|---|
progressiveoperkey={key} (Optional) |
query | Key used to determine the progress of the upload in case of a large file upload |
filename={filename} this is form type parameter. (mandatory parameter) |
form | used to specify the name of the file being uploaded. |
The method should always be used in conjunction with the share file method, otherwise the uploaded file is deleted after 5 days if no share references this file.
Response format
<file>
<fileid>12</fileid>
</file>
Response Codes
Code | Meaning |
---|---|
201 | document uploaded successfully |
401 | Unauthorized |
403 | Validation failed/ Forbidden |
405 | Method not allowed (calling api with wrong method) |
500 | Internal error occured while uploading document |
Jim Page in the use case we discussed, the files will be uploaded to service accounts "My files" and then shared from there.
- You can get the root folder of "My files" by calling "Get Sites", which gives you a list of all sites you have access to, including My Site (You can also filter just by My Site), The site information holds the ID of the root folder of the site.
- Using the root folder of "My Files" you can traverse all folders of "My Files" by using the "Get Folders API". You can also create a new folder using "Add folder" API and then use that to store the files.
Using Add file for Quick share is perfectly fine in your case, however please note that as soon as you share the file, the file is also visible in My Files under "Shared items" option in the left navigation.
So as explained above its your choice to either create a custom folder to store the files by using the method explained above, and hence create separate folder for each user, or just use the "Add file for Quick share" and store all files in the "Shared items" location
Further to discussions with Imran we encountered an issue whereby our back office application would need to upload files to a users folder. This presented two problems:
1. The AddFile method requires a FolderID which our application would not know
2. We would also not know the credentials of the user for the OAuth handshake.
A solution to issue 2 was to set up a Collaborate account which would effectively act as a service account that our application would know the credentials of. This account would issue an AddFiles call and then a ShareViaEmail call. This still poses the problem of not knowing the folderID (although we might be able to record that in our application for the service account). One possible downside of the service account approach is that all files uploaded would be accessible through that account so this could be seen as a security issue.
This brings me on to this method (Add File for Quick Share) which does not require a folder ID, furthermore the files are not viewable through the web interface. Files are temporary for 5 days until one of the ShareFile methods is called. Files are automatically removed once all share references disappear / expire (so its kind of like automatic archiving).
I feel that this method would be perfect for our uses, so my question is, have I understood this method correctly and in our use case, would Add File For Quick Share be a better option than AddFile?
Comments
2 Comments