public static FileUploadResult UploadFile( System.Web.HttpPostedFileBase postedFile)
{
FileUploadResult uploadResult = null;
string fn = "";
TasksApi tasksApi = new TasksApi(Config.Configuration.AppKey, Config.Configuration.AppSID);
try
{
string folderName = Guid.NewGuid().ToString();
// Prepare a path in which the result file will be
string uploadPath = Config.Configuration.WorkingDirectory + "\\" + folderName;
// Check directroy already exist or not
if (!Directory.Exists(uploadPath))
Directory.CreateDirectory(uploadPath);
// Check if File is available.
if (postedFile != null && postedFile.ContentLength > 0)
{
fn = System.IO.Path.GetFileName(postedFile.FileName);
postedFile.SaveAs(uploadPath + "\\" + fn);
}
PostCreateRequest request = new PostCreateRequest(fn,File.OpenRead(uploadPath + "\\" + fn), null);
// Upload original document to Cloud Storage
tasksApi.UploadFile(request);
// Create response
return new FileUploadResult
{
FileName = fn,
FolderId = folderName
};
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
return uploadResult;
}