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;
        }
    }
}