/
DC 5.4 UploadFileChunks
DC 5.4 UploadFileChunks
This method is used for uploading the physical file to the server
URL : /UploadFileChunk.js
Method : POST
Auth required : Yes
Content type : application/octet-stream
Required parameters
Name | Example | Description |
---|---|---|
ItemId | 1234 | ItemId of the upload, returned from InitiateUpload |
jsonresponse | 1 | decides whether the response should be json or xml |
finished | 1/0 | bit that decides if the upload is complete |
AccessKey | AccessKey for authentication |
C# example
/// <summary> /// Uploads the file in chunks. It happens more than often that consumers are uploading files that exceed the 2GB barrier of IIS. /// Therefore we use chucked uploads. The chunk size may be set higher for more performance if the connection is rock solid. /// </summary> /// <param name="filePath">The file path.</param> /// <param name="uploadId">The upload identifier.</param> private void UploadFileChunks(string filePath, string itemId) { var url = "UploadFileChunk.js?accesskey=" + accessKey + "&itemid=" + itemId+ "&jsonresponse=1&finished="; var stopWatch = new Stopwatch(); const int ChunkSize = 1024 * 500; var bytes = new byte[ChunkSize]; int read; var stream = File.OpenRead(filePath); while ((read = stream.Read(bytes, 0, ChunkSize)) > 0) { var finished = (read < ChunkSize) ? "1" : "0"; var req = CreateWebRequest("POST", url + finished, "application/octet-stream"); var resp = ""; var code = HttpStatusCode.ExpectationFailed; try { stopWatch.Start(); using (var streamWriter = new BinaryWriter(req.GetRequestStream())) streamWriter.Write(bytes, 0, read); using (var response = (HttpWebResponse)req.GetResponse()) using (var responseStream = response.GetResponseStream()) { code = response.StatusCode; if (responseStream != null) { using (var reader = new StreamReader(responseStream)) resp = reader.ReadToEnd(); } } stopWatch.Stop(); } finally { log.Debug($"{nameof(UploadFileChunks)} {Convert.ToInt32(code)}: Request completed in {stopWatch.ElapsedMilliseconds} ms (accumulated), Response: {resp}, using {req.RequestUri}"); } } }
, multiple selections available,
Related content
DC 5.4 InitiateUpload
DC 5.4 InitiateUpload
Read with this
DC 5.7 UploadFileChunks
DC 5.7 UploadFileChunks
More like this
DC 5.4 Setting metadata on an asset
DC 5.4 Setting metadata on an asset
Read with this
DC 5.5 UploadFileChunks
DC 5.5 UploadFileChunks
More like this
DC 5.4 Upload/Replace
DC 5.4 Upload/Replace
Read with this
DC 5.6 UploadFileChunks
DC 5.6 UploadFileChunks
More like this