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