使用Go 上傳檔案到AWS S3
挑戰:
挑戰:挑戰:
挑戰:
挑戰:
import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3/s3manager" ) func main() { // Create an S3 uploader with custom options uploader := s3manager.NewUploader(session.Must(session.NewSession()), func(u *s3manager.Uploader) { u.PartSize = 5 * 1024 * 1024 // 5MB part size u.Concurrency = 2 // 2 concurrent uploads }) // Open the file for upload f, err := os.Open("file.txt") if err != nil { panic(err) } defer f.Close() // Stream file to S3 result, err := uploader.Upload(&s3manager.UploadInput{ Bucket: aws.String("my-bucket"), Key: aws.String("file.txt"), Body: f, }) if err != nil { panic(err) } // Display uploaded file information fmt.Printf("File uploaded to: %s", result.Location) }
以上是如何使用 Go 將大檔案串流傳輸到 AWS S3?的詳細內容。更多資訊請關注PHP中文網其他相關文章!