آپلود یک بخش از آپلود چندبخشی برای یک آبجکت
مولفهها
- کلیدهای احراز هویت
- نام صندوقچه
- نام آبجکت
- شماره بخش
- شناسه آپلود
- NET.
- PHP
- Python
- Javascript
- GO
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace UploadPart
{
class UploadPart
{
private const string bucketName = "<BUCKET_NAME>";
private const string objectName = "<OBJECT_NAME>";
private static IAmazonS3 _s3Client;
public static void Main()
{
var awsCredentials = new Amazon.Runtime.BasicAWSCredentials("<ACCESS-KEY>", "<SECRET-KEY>");
var config = new AmazonS3Config { ServiceURL = "<ENDPOINT>" };
_s3Client = new AmazonS3Client(awsCredentials, config);
UploadPartAsync().Wait();
}
private static async Task UploadPartAsync()
{
try
{
UploadPartRequest uploadRequest = new UploadPartRequest
{
BucketName = bucketName,
Key = objectName,
UploadId = "123",
PartNumber = 1,
};
UploadPartResponse up1Response = await _s3Client.UploadPartAsync(uploadRequest);
Console.WriteLine($"Upload part completed");
}
catch (AmazonS3Exception amazonS3Exception)
{
Console.WriteLine("An AmazonS3Exception was thrown. Exception: " + amazonS3Exception.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.ToString());
}
}
}
}
<?php
require('client.php');
$bucket = '<BUCKET_NAME>';
try {
$result = $client->uploadPart([
'Bucket' => $bucket, // REQUIRED
'ContentLength' => 0,
'ContentSHA256' => '<string>',
'ExpectedBucketOwner' => '<string>',
'Key' => '<OBJECT_NAME>', // REQUIRED
'PartNumber' => 0, // REQUIRED
'RequestPayer' => 'requester',
'SSECustomerAlgorithm' => '<string>',
'SSECustomerKey' => '<string>',
'SSECustomerKeyMD5' => '<string>',
'SourceFile' => '<string>',
'UploadId' => '<string>', // REQUIRED
]);
var_dump($result);
} catch (AwsException $e) {
// Display error message
echo $e->getMessage();
echo "\n";
}
import boto3
import logging
from datetime import datetime
from botocore.exceptions import ClientError
logging.basicConfig(level=logging.INFO)
try:
s3_client = boto3.client(
's3',
endpoint_url='<ENDPOINT>',
aws_access_key_id='<ACCESS-KEY>',
aws_secret_access_key='<SECRET-KEY>'
)
except Exception as exc:
logging.error(exc)
else:
try:
response = s3_client.upload_part(
Bucket='<BUCKET_NAME>',
ContentLength=123,
ContentMD5='string',
Key='<OBJECT_NAME>',
PartNumber=123,
UploadId='string',
SSECustomerAlgorithm='string',
SSECustomerKey='string',
RequestPayer='requester',
ExpectedBucketOwner='string'
)
logging.info(response)
except ClientError as exc:
logging.error(exc)
// Import required AWS SDK clients and commands for Node.js
const { S3Client, UploadPartCommand } = require("@aws-sdk/client-s3");
// Create an S3 client service object
const s3 = new S3Client({
region: "default",
endpoint: "<ENDPOINT_URL>",
credentials: {
accessKeyId: "<ACCESS_KEY>",
secretAccessKey:
"<SECRET_KEY>",
},
});
const BUCKET_NAME = "<BUCKET_NAME>";
const run = async () => {
try {
const response = await s3.send(
new UploadPartCommand({
Bucket: BUCKET_NAME,
Key: "<OBJECT_NAME>",
UploadId: "ID",
PartNumber: 123,
})
);
console.log("Success", response);
} catch (err) {
console.log("Error", err);
}
};
run();
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"fmt"
"os"
)
// Upload part
//
// Usage:
// go run s3_upload_part.go BUCKET OBJECT
func main() {
if len(os.Args) != 3 {
exitErrorf("Bucket and object names required\nUsage: go run", os.Args[0], "BUCKET OBJECT")
}
bucket := os.Args[1]
key := os.Args[2]
// Initialize a session in us-west-2 that the SDK will use to load
// credentials from the shared credentials file ~/.aws/credentials.
sess, err := session.NewSession(&aws.Config{
Credentials: credentials.NewStaticCredentials("<ACCESS-KEY>", "<SECRET-KEY>", ""),
})
svc := s3.New(sess, &aws.Config{
Region: aws.String("default"),
Endpoint: aws.String("<ENDPOINT>"),
})
params := &s3.UploadPartInput{
Bucket: &bucket,
Key: &key,
PartNumber: aws.Int64(1),
UploadId: aws.String("xadcOB_7YPBOJuoFiQ9cz4P3Pe6FIZwO4f7wN93uHsNBEw97pl5eNwzExg0LAT2dUN91cOmrEQHDsP3WA60CEg--"),
}
// Upload part
result, err := svc.UploadPart(params)
if err != nil {
exitErrorf(err.Error())
}
fmt.Println(result)
}
func exitErrorf(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg+"\n", args...)
os.Exit(1)
}
برای اجرای قطعه کد بالا با فرض نامگذاری فایل کد به s3_upload_part.go میتوان از دستور زیر استفاده کرد:
go run s3_upload_part.go BUCKET_NAME OBJECT_NAME