对象相关接口 请求参数 PutObjectTagging可设置的参数如下: 参数 类型 说明 是否必要 BucketName string 设置标签信息的对象所在桶的名称 是 Key string 设置标签信息的对象的key 是 VersionId string 设置标签信息的对象的version id 否 生成上传预签名URL 功能说明 GetPreSignedURL接口为一个指定对象生成一个预签名的上传链接,访问该链接可以直接上传对象。 代码示例 生成上传预签名URL: plaintext public string GeneratePutUrl() { Console.Out.WriteLine("generateUploadUrl"); GetPreSignedUrlRequest request new GetPreSignedUrlRequest { BucketName " ", Key " ", Expires DateTime.Now.AddMinutes(5), Protocol Protocol.HTTP, //Protocol.HTTP or Protocol.HTTPS Verb HttpVerb.PUT, // 设置 HTTP 方法为 PUT,用于上传 ContentType "application/octetstream" // 指定 ContentType }; string url this.s3Client.GetPreSignedURL(request); Console.Out.WriteLine("generateUploadUrl: {0}", url); return url; } 通过该预签名URL,可以直接将文件上传到指定的桶: plaintext public void PutObjUsingPresignedUrl(string url, string filePath) { try { using (WebClient client new WebClient()) { client.Headers.Add("ContentType", "application/octetstream"); client.UploadFile(url, "PUT", filePath); } Console.WriteLine("Upload successful. File uploaded from: " + filePath); } catch (Exception ex) { Console.WriteLine("Upload failed: " + ex.ToString()); } } 请求参数 参数 类型 说明 是否必要 BucketName string 桶的名称 是 Key string 对象的key 是 Expires DateTime 超时的时间戳 否 Protocol Protocol 指定生成的URL使用http协议还是https协议 否 Verb HttpVerb HTTP 方法,设置为 PUT 以生成上传 URL,默认为GET 否 ContentType String 对象的ContentType 否。若生成预签名URL时指定了,则通过预签名链接上传时也需要指定为相同的ContentType
来自: