The specified upload session # does not exist - Randomly thrown when uploading documents

The attached code randomly throws the following error: 

{"ErrorCode":"11","Status":404,"URL":"/objects/0","Method":"POST","Exception":{"Name":"COMException","Message":"Not found. (The specified upload session 1 does not exist.)","InnerException":{"Name":"MFilesException","Message":"Not found. (The specified upload session 1 does not exist.)","StackText":"Error reference ID: 1c32dda2-06a9-4daa-b684-758072d379e6","ErrorCode":"11"}},"Stack":"Error reference ID: 1c32dda2-06a9-4daa-b684-758072d379e6","Message":"Not found. (The specified upload session 1 does not exist.)","IsLoggedToVault":true,"IsLoggedToApplication":true,"ExceptionName":"COMException"}

In every case a UploadID is returned so I know that it's not null when this error is thrown.
I get:
 {
"UploadID":1,
"Title":"33a04367-6c66-44be-8d31-b2f40c972192",
"Extension":"pdf",
"Size":720643,
"FileInformationType":0,
"TempFilePath":""
}

Is there something wrong with my code or do I need to configure something for this to be reliable?

public async Task<(string docId, string errMsg)> oAuthDocumentUpload(string uri, string VaultGUID, string ConnectionName, ObjectCreationModel? obj, string filePath,string token)
{
    if (VaultGUID.Contains("{"))
        VaultGUID = VaultGUID.Replace("{", "").Replace("}", "");
    var options = new RestClientOptions(uri)
    {
       Timeout=TimeSpan.FromMinutes(2),
    };
    var client = new RestClient(uri);

    var uploadRequest = new RestRequest("/REST/files", Method.Post);
    uploadRequest.AddHeader("Content-Type", "multipart/form-data");
    uploadRequest.AlwaysMultipartFormData = true;
    uploadRequest.AddFile("file", filePath);
    uploadRequest.AddHeader("Authorization", "Bearer " + token);
    uploadRequest.AddHeader("X-AuthConfig", ConnectionName);
    uploadRequest.AddHeader("X-Vault", VaultGUID);
    

    var uploadResponse = await client.ExecuteAsync(uploadRequest);
    if (!uploadResponse.IsSuccessful)
    {
        _log.Error($"File upload failed: {uploadResponse.ErrorException}");
        return ("", $"File upload failed: {uploadResponse.ErrorException}");
    }
    var uploadInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<UploadInfo>(uploadResponse.Content);

    

    uploadInfo.Extension = Path.GetExtension(filePath).TrimStart('.').ToLower();
    //uploadInfo.UploadID
    obj.Files = new[] { uploadInfo };
    
    var requestCreateObject = new RestRequest("/REST/objects/0", Method.Post); 

    requestCreateObject.AddJsonBody(obj);
    requestCreateObject.AddHeader("Authorization", "Bearer " + token);
    requestCreateObject.AddHeader("X-AuthConfig", ConnectionName);
    requestCreateObject.AddHeader("X-Vault", VaultGUID);


    var createObjectResponse =await client.ExecuteAsync(requestCreateObject);
    if (!createObjectResponse.IsSuccessful)
    {
        Console.WriteLine($"Object creation failed: {createObjectResponse.ErrorException}");
        _log.Error($"Object creation failed: {createObjectResponse.ErrorException}");
        return ("", $"File upload failed: {createObjectResponse.ErrorException}");
    }

    var objectVersion = Newtonsoft.Json.JsonConvert.DeserializeObject<ObjectVersion>(createObjectResponse.Content);
    string mfilesDocId = objectVersion?.ObjVer?.ID != null
    ? objectVersion.ObjVer.ID.ToString()
    : string.Empty;

    return (mfilesDocId, "");

}

Parents Reply
  • Thanks Joonas - yes, this is it.  It gets missed sometimes when people use other authentication approaches because the issue isn't so obvious, but it's exactly the same thing.  Always ensure that you include all cookies (not just the two listed in the code snippet from Abitofbyte) just to make this future-proof, although there is work ongoing to hopefully make it not needed in the future.

Children
No Data