/
DC5.0.0 6.4.3 - UploadFileChunks

DC5.0.0 6.4.3 - 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

NameExampleDescription
uploadId1234id of the upload
jsonresponse1decides whether the response should be json or xml
finished1/0bit that decides if the upload is complete


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 uploadId)
{
    var url = "UploadFileChunk.js?accesskey=" + accessKey + "&uploadid=" + uploadId + "&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}");
        }
    }
}

Related content

DC 5.7 UploadFileChunks
DC 5.7 UploadFileChunks
More like this
DC 5.9 UploadFileChunks
DC 5.9 UploadFileChunks
More like this
DC 5.6 UploadFileChunks
DC 5.6 UploadFileChunks
More like this
DC 5.10 UploadFileChunks
DC 5.10 UploadFileChunks
More like this
DC 5.4 UploadFileChunks
DC 5.4 UploadFileChunks
More like this
DC 5.5 UploadFileChunks
DC 5.5 UploadFileChunks
More like this