Search code examples
autodeskautodesk-forgeautodesk-data-management

UploadChunk Autodesk API


What am i doing wrong? I have the autorization, I have the bucket, I have the file but i can't upload it, and it's too large to use UploadObject.

here's the part of the upload of my code

using (StreamReader streamReader = new StreamReader(filePath))
            {   Byte[] buffer = new Byte[2097153];
                var QtdeBytesFaltantes = streamReader.BaseStream.Length;
                var byteInicio = 0;
                var byteFim = 0;
                while (QtdeBytesFaltantes > 0)
                {
                    byteFim = await streamReader.BaseStream.ReadAsync(buffer, 0, buffer.Length);
                    await objectsApi.UploadChunkAsync(bucketKey,
                        Path.GetFileName(filePath),
                        (int)streamReader.BaseStream.Length,
                        "bytes " + byteInicio + "-" + byteFim + "/" + (int)streamReader.BaseStream.Length,
                        "IdUnicoDaSessao",
                        streamReader.BaseStream);

                    QtdeBytesFaltantes -= buffer.Length;
                    byteInicio = byteFim + 1;
                }

                dynamic response = await objectsApi.GetObjectAsync(bucketKey, Path.GetFileName(filePath));

                return response;

Solution

  • Seems you are using the .Net Forge SDK and C#.

    An example to use chunks is located here

    A chunk needs to be at least 2Mb (we recommend minimum 5Mb, but 2Mb is enforced by the system). Only the last piece can be less than 2 Mb - see this article for details.

    Seems your math to calculate chunk length isn't correct, when using the sample listed above, I do print the chunks range defintions, so you can compare with yours.

    Hope it helps,