Before you can use the Aspose.Words Cloud API (or other Aspose Cloud APIs) to read and update existing documents the files will need to be loaded into the Storage in the cloud.
The Aspose.Storage Cloud API can be directly accessed via the REST API but this sample will use the Cloud SDK for .NET to make the code simpler.
To begin you will need the SDK downloaded (either the DLL or the source code) and to sign up for a set of credentials by creating an account and requesting a set of API keys. See https://dashboard.aspose.cloud/
The sample code below shows a simple function to upload a file to Storage by supplying your API keys, local file name and where you want to store the file on Storage.
The essential steps are to:
- Open the StorageApi using your app keys
- Create a PutCreateRequest and pass in details of the file
- Call the PutCreate method
- Check the result
using System; | |
using System.IO; | |
using Aspose.Storage.Cloud.Sdk.Api; | |
using Aspose.Storage.Cloud.Sdk.Model; | |
using Aspose.Storage.Cloud.Sdk.Model.Requests; | |
namespace AsposeSamples | |
{ | |
public class StorageSample | |
{ | |
/// <summary> | |
/// UploadFile - Upload local file to storage so that API calls can process the file. | |
/// See https://dashboard.aspose.cloud/ for details on creating your app and getting your App Sid and App Key. | |
/// </summary> | |
/// <param name="appSid"></param> | |
/// <param name="appKey"></param> | |
/// <param name="localFileName">Local or UNC path to local file name</param> | |
/// <param name="remoteFileName">Remote file name </param> | |
/// <param name="remoteFolderName">Remote file path with foward-slash delimiters</param> | |
/// <param name="storageName">'First Storage' is the default for new apps. See https://dashboard.aspose.cloud/ to manage stoage</param> | |
/// <returns></returns> | |
private static bool UploadFile(string appSid, string appKey, string localFileName, | |
string remoteFileName, string remoteFolderName, string storageName) | |
{ | |
bool fileOk = false; | |
// 1 - Open the Storage API using your app Key and Sid | |
var storageApi = new StorageApi(appKey, appSid); | |
using (Stream fs = File.OpenRead(localFileName)) | |
{ | |
// 2 - Create a put request with the file details | |
PutCreateRequest putRequest = new Aspose.Storage.Cloud.Sdk.Model.Requests.PutCreateRequest( | |
$"{remoteFolderName}/{remoteFileName}", fs, null, storageName | |
); | |
// 3 - Upload the file | |
UploadResponse uploadResponse = storageApi.PutCreate(putRequest); | |
// 4 - Check the response status and feed that back to calling code. | |
if (uploadResponse.Status.ToUpper() == "OK") | |
{ | |
fileOk = true; | |
} | |
} | |
return fileOk; | |
} | |
} | |
} |
Top comments (0)