Clients may call getDownloadUrl
which returns a URL that can be invoked at a later time.
getDownloadUrl
Call getDownloadUrl
to retrieve a URL hat can be invoked at a later time.
Code Sample
var url = cloud.getDownloadUrl('/path/to/file.jpg');
//Use jQuery to set a hyperlink dynamically
$('a').attr('href',url);
```
## File Upload
While uploading files which are only a few hundred of kilobytes in size on a standard connection typically does not pose any difficulties, this often might not be the case for your users. Your app should be able to upload large files, such as videos efficiently. It should also be able to recover from interrupted uploads that might be caused by mobile connectivity issues or power outages, without having to restart the upload process.
Chunked file uploads allow you to break a large file into small chunks, and then send these pieces to the upload server one-by-one. If an upload were to fail, your app would not have to resend the whole file. It can resume the file upload from the last successfully sent chunk.
**NOTE:**
You cannot perform the file upload operation on a [virutal folder](../../API_Developer_Guide/About_Virtual_Folders/).
### Non-Chunked File Upload
1. Call [`fileuploadIntent`](../../Node.js_Reference/File_and_Folder_Operations/) to let the system know that you intend to upload a file. Set the `chunk` parameter to *false*.
2. Upload the file using the library of your choice.
**Code Sample**
```javascript
cloud.fileuploadIntent({
checksum: sha256, //sha256 checksum of the file
chunk: false,
name: 'somefile.txt',
path: '/VZMOBILE/someDirectory',
size: file.size,
success: function(success) {
var uploadUrl = success.body.uploadurls.uploadurl;
//now actually upload the file using the library of your choice
Upload.http({
url: uploadUrl + "&checksum=" + encodeURIComponent(sha256),
data: file,
headers: {
'Authorization': 'Bearer ' + cloud.getAuth().authToken,
'Content-Type': 'application/octet-stream'
},
})
}
});
fileuploadIntent
to let the system know that you intend to upload a file. Set the chunk
parameter to true.commitChunkedUpload
to finalize the chunked file upload.Code Sample
cloud.fileuploadIntent({
checksum: sha256, //sha256 checksum of the file
chunk: true, //note chunk is set to true
name: 'somefile.txt',
path: '/VZMOBILE/someDirectory',
size: file.size,
success: function(success) {
var uploadUrl = success.body.uploadurls.uploadurl;
//used to tell the server you're done uploading chunks
var commiturl = success.body.uploadurls.commiturl;
//Upload the file in chunks using the library of your choice
var chunksUploaded = 0;
for(var c = 1; c <= numberOfChunks; c++) {
Upload.http({
url: uploadUrl + "&checksum=" + encodeURIComponent(sha256),
data: getChunk(file, c),
headers: {
'Authorization': 'Bearer ' + cloud.getAuth().authToken,
'Content-Type': 'application/octet-stream'
},
}).then(function(resp) {
chunksUploaded++;
//Once all chunks have been uploaded, finalze the chunked file upload.
if(chunksUploaded == numberOfChunks) {
cloud.commitChunkedUpload({
commiturl: commiturl,
success: function(success) {
//done uploading in chunks
}
});
}
});
}
});
You can call fullview
method to download the information on all files and folders within a user’s Personal Cloud Storage account.
A successful cal to fullview
returns an ‘x-header-etag’. You can use the ‘x-header-etag’ to retrieve the changes to the files and folders made between two fullview
calls.
The following code sample shows a call to fullview
.
Code Sample
cloud.fullview({
success: function(success) {
var files = success.body.data.file;
var folders = success.body.data.folder;
var etag = success.headers['x-header-etag'];
}
});
The following code sample uses the ‘x-header-etag’ retrieved from a previous fullview
call. The result of this call is the information on all files and folders that have been changed since the previous fullview
call.
Code Sample
cloud.fullview({
etag: etag, // retrieved from previous fullview call
success: function(success) {
var filesDelta = success.body.data.file;
var foldersDelta = success.body.data.folder;
//the new etag should be passed into subsequent fullviews
var newEtag = success.headers['x-header-etag'];
}
});
You can download thumbnails of a file by calling getThumbnailUrl
method.
getThumbnailUrl
To retrieve thumbnail of a file, you will need to provide the file’s contentToken
. The content token is contained in the response to a call to fullview
or metadata
API.
Code Sample
var size = 32; //width and height of the thumbnail in pixels
//you can retrieve the contentToken from any fullview or metadata call;
var thumbnailUrl = cloud.getThumbnailUrl(contentToken, size);
Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.