Skip to content

Commit

Permalink
fix: Upload pictures was refused by policy
Browse files Browse the repository at this point in the history
  • Loading branch information
kumy committed Oct 3, 2023
1 parent d550926 commit b26e78d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ $("div#geokretAvatar").dropzone({
},

sending: function (file, xhr, formData) {
for (let key in file.postData) {
let includes = ['key', 'X-Amz-Credential', 'X-Amz-Algorithm', 'X-Amz-Date', 'Policy', 'X-Amz-Signature'];
for (let key of includes) {
if (file.postData.hasOwnProperty(key)) {
formData.append(key, file.postData[key]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ $('div.enable-dropzone').each(function() {
},

sending: function (file, xhr, formData) {
for (let key in file.postData) {
let includes = ['key', 'X-Amz-Credential', 'X-Amz-Algorithm', 'X-Amz-Date', 'Policy', 'X-Amz-Signature'];
for (let key of includes) {
if (file.postData.hasOwnProperty(key)) {
formData.append(key, file.postData[key]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ $("div#userAvatar").dropzone({
},

sending: function (file, xhr, formData) {
for (let key in file.postData) {
let includes = ['key', 'X-Amz-Credential', 'X-Amz-Algorithm', 'X-Amz-Date', 'Policy', 'X-Amz-Signature'];
for (let key of includes) {
if (file.postData.hasOwnProperty(key)) {
formData.append(key, file.postData[key]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ public function request_s3_file_signature(\Base $f3) {
$s3 = S3Client::instance()->getS3Public();

$formInputs = [
'acl' => 'private',
's3Key' => $this->getImgKey(),
'key' => $this->getFullImgKey(),
];

// Related docs:
// https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html
// https://docs.aws.amazon.com/AmazonS3/latest/dev/HTTPPOSTForms.html#HTTPPOSTConstructPolicy
$options = [
['acl' => 'private'],
['bucket' => GK_BUCKET_NAME_PICTURES_PROCESSOR_DOWNLOADER],
['eq', '$key', $this->getFullImgKey()],
['content-length-range', 1024, 1024 * 1024 * GK_SITE_PICTURE_UPLOAD_MAX_FILESIZE],
Expand All @@ -46,6 +43,7 @@ public function request_s3_file_signature(\Base $f3) {
[
'success' => true,
'uploadUrl' => $formAttributes['action'],
's3Key' => $this->getImgKey(),
],
$formInputs
);
Expand Down

0 comments on commit b26e78d

Please sign in to comment.