Docs Menu

AWS S3 Snippets [Deprecated]

重要

サードパーティ サービスとプッシュ通知の廃止

Atlas App Services のサードパーティ サービスとプッシュ通知は非推奨となり、代わりに関数内の外部依存関係を使用する HTTP エンドポイントを作成できるようになりました。

Webhook はHTTPS endpointsに名前変更され、動作は変更されません。 既存の Webhook を移行する必要があります。

既存のサービスは、 30、2025 まで引き続き機能します。

サードパーティ サービスとプッシュ通知は非推奨になったため、App Services UI からデフォルトで削除されました。 既存のサードパーティ サービスまたはプッシュ通知を管理する必要がある場合は、次の操作を実行して構成を UI に追加できます。

  • 左側のナビゲーションの [ Manage ] セクションの下にある [ App Settings ] をクリックします。

  • Temporarily Re-Enable 3rd Party Servicesの横にあるトグル スイッチを有効にし、変更を保存します。

The code snippets on this page demonstrate how to work with Amazon Simple Storage Service through the Amazon Web Services Service. All of the snippets require an AWS Service interface with a configuration of AWS Service rules that allow the service actions used in the snippet. You can run these snippets yourself by copying this code into an Atlas Function.

If your app does not have an AWS Service interface, create one before using these snippets.

This Atlas Function uploads a Base64 encoded image to AWS S3 using the PutObject action.

exports = function(base64EncodedImage, bucket, fileName, fileType) {
// Convert the base64 encoded image string to a BSON Binary object
const binaryImageData = BSON.Binary.fromBase64(base64EncodedImage, 0);
// Instantiate an S3 service client
const s3Service = context.services.get('myS3Service').s3('us-east-1');
// Put the object to S3
return s3Service.PutObject({
'Bucket': bucket,
'Key': fileName,
'ContentType': fileType,
'Body': binaryImageData
})
.then(putObjectOutput => {
console.log(putObjectOutput);
// putObjectOutput: {
// ETag: <string>, // The object's S3 entity tag
// }
return putObjectOutput
})
.catch(console.error);
};
Parameter
タイプ
説明

base64EncodedImage

string

A Base64 encoded image. You can convert an image ファイル to Base64 with the readAsDataURL method from the FileReader Web API.

bucket

string

The name of the S3 bucket that will hold the image.

fileName

string

The name of the image file, including its file extension.

fileType

string

The MIME Type of the image.

This Atlas Function retrieves an object from AWS S3 using the GetObject action.

exports = function(bucket, fileName) {
// Instantiate an S3 service client
const s3Service = context.services.get('myS3Service').s3('us-east-1');
// Get the object from S3
return s3Service.GetObject({
'Bucket': bucket,
'Key': fileName,
})
.then(getObjectOutput => {
console.log(getObjectOutput);
// {
// ETag: <string>, // The object's S3 entity tag
// Body: <binary>, // The object data
// ContentType: <string>, // The object's MIME type
// }
const base64EncodedImage = getObjectOutput.Body
return base64EncodedImage
})
.catch(console.error);
};
Parameter
タイプ
説明

bucket

string

The name of the S3 bucket that will hold the image.

fileName

string

The name of the image file, including its file extension.