public override async Task <string> SaveAsync(FileSetOptions fileSetOptions) { CloudStorageAccount storageAccount = Authorized(fileSetOptions); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(fileSetOptions.Folder.ToLower()); if (await container.CreateIfNotExistsAsync()) { if (fileSetOptions.FileAccess == FileAccessLevel._public) { var publicAccess = BlobContainerPublicAccessType.Blob; var sharedAccessPolicies = new SharedAccessBlobPolicy { Permissions = SharedAccessBlobPermissions.Read, }; await container.SetPermissionsAsync(new BlobContainerPermissions() { PublicAccess = publicAccess }); } } CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileSetOptions.Key); fileSetOptions._stream.Seek(0, SeekOrigin.Begin); await blockBlob.UploadFromStreamAsync(fileSetOptions._stream); return(fileSetOptions.Key); }
public override async Task <string> SaveAsync(FileSetOptions fileSetOptions) { GoogleCredential credential = await AuthorizedAsync(fileSetOptions); StorageClient storageClinet = await StorageClient.CreateAsync(credential); PredefinedObjectAcl predefinedObjectAcl = PredefinedObjectAcl.ProjectPrivate; PredefinedBucketAcl predefinedBucketAcl = PredefinedBucketAcl.ProjectPrivate; switch (fileSetOptions.FileAccess) { case FileAccessLevel._private: predefinedObjectAcl = PredefinedObjectAcl.AuthenticatedRead; predefinedBucketAcl = PredefinedBucketAcl.AuthenticatedRead; break; case FileAccessLevel._public: predefinedObjectAcl = PredefinedObjectAcl.PublicRead; predefinedBucketAcl = PredefinedBucketAcl.PublicRead; break; } if (fileSetOptions.folderOptions == FolderOptions.CreateIfNull) { var folder = await storageClinet.GetBucketAsync(fileSetOptions.Folder); if (folder == null) { await storageClinet.CreateBucketAsync(fileSetOptions.ProjectId, fileSetOptions.Folder, new CreateBucketOptions() { PredefinedAcl = predefinedBucketAcl, PredefinedDefaultObjectAcl = predefinedObjectAcl }); } } fileSetOptions._stream.Position = 0; await storageClinet.UploadObjectAsync(fileSetOptions.Folder, fileSetOptions.Key, fileSetOptions.ContentType, fileSetOptions._stream, new UploadObjectOptions() { PredefinedAcl = predefinedObjectAcl }); return(fileSetOptions.Key); }
public async override Task <string> SaveAsync(FileSetOptions fileSetOptions) { string subAddress = Path.Combine(fileSetOptions.Address, fileSetOptions.Folder); string fileAddress = Path.Combine(subAddress, fileSetOptions.Key); if (fileSetOptions.folderOptions == Enum.FolderOptions.CreateIfNull) { if (Directory.Exists(subAddress) == false) { Directory.CreateDirectory(subAddress); } } using (FileStream fs = new FileStream(fileAddress, FileMode.Create, FileAccess.Write)) { fileSetOptions._stream.Position = 0; await fileSetOptions._stream.CopyToAsync(fs); } return(fileSetOptions.Key); }
public override async Task <string> SaveAsync(FileSetOptions fileSetOptions) { FileData file = new FileData(); CloudStorageAccount storageAccount = Authorized(fileSetOptions); CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); CloudFileShare fileshare = fileClient.GetShareReference(fileSetOptions.Folder); await fileshare.CreateIfNotExistsAsync(); CloudFileDirectory cFileDir = fileshare.GetRootDirectoryReference(); await cFileDir.CreateIfNotExistsAsync(); CloudFile cFile = cFileDir.GetFileReference(fileSetOptions.Key); fileSetOptions._stream.Position = 0; await cFile.UploadFromStreamAsync(fileSetOptions._stream); return(fileSetOptions.Key); }
public abstract Task <string> SaveAsync(FileSetOptions fileSetOptions);