0

We have a small program, to upload some files to Softlayer through object storage's Rest API.

Every day we upload about 38 files, with 1.32 GB total size. The files sizes vary between 650KB to 600MB, approximately.

One of those files have ~582MB size, and every day our program tries three times to upload it, but it has always been unsuccessful. This file takes about 30~45 minutes long to be upload, each attempt.

The message returned by the API is:

The request was aborted: The request was canceled.

Here is my code to Upload the files:

// Lists the Backup files of the folder
DirectoryInfo dirInfoBkps = new DirectoryInfo(backupFolder);
FileInfo[] arrFiles = dirInfoBkps.GetFiles(backupExtension);

// Performs the authentication in Softlayer, and obtains the Token and URL of Upload
RestHelper softlayerRestAPI = new RestHelper();
softlayerRestAPI.RestHeaders.Add("X-Auth-User", apiSoftlayerUser);
softlayerRestAPI.RestHeaders.Add("X-Auth-Key", apiSoftlayerToken);
softlayerRestAPI.RestHeaders.Add("X-Account-Meta-Temp-Url-Key", apiSoftlayerMetaTempUrlKey);

Dictionary<string, string> dicRespondeHeaders;
SoftlayerModel softlayerModel =
    softlayerRestAPI.CallGetRestMethod<SoftlayerModel>(apiSoftlayerUrl, out dicRespondeHeaders);

// Prepares to Upload Files
apiSoftlayerUrl = softlayerModel.storage.@public;
apiSoftlayerUrl = apiSoftlayerUrl.Replace("https", "http");

apiSoftlayerXAuthToken = dicRespondeHeaders["X-Storage-Token"];

// Upload each file in the folder
foreach (FileInfo fileInfo in arrFiles)
{
    // Creates the Upload URL
    string uploadUrl = string.Format("{0}{1}{2}",
        apiSoftlayerUrl,
        "/Backups_SVN/",
        fileInfo.Name);

    // Try to make the upload 3-times 
    int numberOfTries = 0;
    Exception lastException = null;
    string lastFilename = null;
    string mensagem = string.Empty;
    while (numberOfTries < 3)
    {
        try
        {
            numberOfTries++;

            softlayerRestAPI.RestHeaders.Clear();
            softlayerRestAPI.RestHeaders.Add("X-Auth-Token", apiSoftlayerXAuthToken);
            byte[] arr =
                softlayerRestAPI.CallUploadRestMethod(uploadUrl, fileInfo.FullName);

            // Upload Successful
            break;
        }
        catch (Exception ex)
        {
            // Upload failed
            lastException = ex;
            lastFilename = fileInfo.Name;

            Console.WriteLine(ex.Message);
        }
    }

    if (numberOfTries == 3) // All attempts failed
    {
        // Writes the error log for future reference
    }
}

Update

I forgot the code for RestHelper class: https://pastebin.com/hBYjXXJh

  • 1
    Possible duplicate of [HttpWebRequest: The request was aborted: The request was canceled](https://stackoverflow.com/questions/2459241/httpwebrequest-the-request-was-aborted-the-request-was-canceled) – Blue Jan 17 '18 at 18:43
  • do you get the same result when you use the control portal (UI ) to submit the issue? it may be an issue with softlayer and not your code – Nelson Raul Cabero Mendoza Jan 17 '18 at 19:45
  • @NelsonRaulCaberoMendoza, I've opened a ticket on Softlayer's Support, and they've said that the problem is in my application, not in theirs API.... And they have asked to me post my doubt here, in StackOverflow... ¬¬ – Mario C Simão Jr Jan 18 '18 at 11:17
  • @MarioCSimãoJr well sorry Mario I am not an expert on C# I only can send you some documentation such as this https://sldn.softlayer.com/blog/waelriac/managing-softlayer-object-storage-through-rest-apis or recomend you to use a Softlayer client for object storage that are available here https://github.com/softlayer?utf8=%E2%9C%93&q=object+storage&type=&language= – Nelson Raul Cabero Mendoza Jan 18 '18 at 13:26
  • @NelsonRaulCaberoMendoza, thank you for attention. My program already implements the steps described by the link you sent. I've looked the client libraries you sent too, but none of then are for .NET... But's Okay, now it's everything working fine... Thanks again for the help. – Mario C Simão Jr Jan 19 '18 at 11:32

1 Answers1

0

@FrankerZ is right - the problem posted here is duplicated with the other post.

I made the procedures of the the other post, and increased the Timeout of my WebRequest object, and the problem was solved.

Thanks for the help.