Share via


你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

CloudBlockBlob.UploadFromFile 方法

定义

将文件上传到 Blob 服务。 如果 Blob 已存在,则会覆盖该 Blob。

[Microsoft.Azure.Storage.DoesServiceRequest]
public virtual void UploadFromFile (string path, Microsoft.Azure.Storage.AccessCondition accessCondition = default, Microsoft.Azure.Storage.Blob.BlobRequestOptions options = default, Microsoft.Azure.Storage.OperationContext operationContext = default);
[<Microsoft.Azure.Storage.DoesServiceRequest>]
abstract member UploadFromFile : string * Microsoft.Azure.Storage.AccessCondition * Microsoft.Azure.Storage.Blob.BlobRequestOptions * Microsoft.Azure.Storage.OperationContext -> unit
override this.UploadFromFile : string * Microsoft.Azure.Storage.AccessCondition * Microsoft.Azure.Storage.Blob.BlobRequestOptions * Microsoft.Azure.Storage.OperationContext -> unit
Public Overridable Sub UploadFromFile (path As String, Optional accessCondition As AccessCondition = Nothing, Optional options As BlobRequestOptions = Nothing, Optional operationContext As OperationContext = Nothing)

参数

path
String

包含提供 Blob 内容的文件路径的字符串。

accessCondition
AccessCondition

一个 AccessCondition 对象,表示继续处理请求而必须满足的条件。

options
BlobRequestOptions

一个 BlobRequestOptions 对象,它指定请求的其他选项。 如果 null为 ,则默认选项应用于请求。

operationContext
OperationContext

一个 OperationContext 对象,它一个表示当前操作的上下文。

实现

属性

示例

// This is one common way of creating a CloudStorageAccount object. You can get 
// your Storage Account Name and Key from the Azure Portal.
StorageCredentials credentials = new StorageCredentials(accountName, accountKey);
CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, useHttps: true);

// Another common way to create a CloudStorageAccount object is to use a connection string:
// CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// This call creates a local CloudBlobContainer object, but does not make a network call
// to the Azure Storage Service. The container on the service that this object represents may
// or may not exist at this point. If it does exist, the properties will not yet have been
// popluated on this object.
CloudBlobContainer blobContainer = blobClient.GetContainerReference(containerName);

// This makes an actual service call to the Azure Storage service. Unless this call fails,
// the container will have been created.
blobContainer.Create();

// This also does not make a service call, it only creates a local object.
CloudBlockBlob blob = blobContainer.GetBlockBlobReference(blobName);

// This transfers data in the file to the blob on the service.
blob.UploadFromFile(inputFileName);

适用于