目前我正在将froala集成到我的项目中(在angualarJs和laravel中)。我需要将图像上传到amazonS3。但是我对amazoneS3路径有一些问题。这是我的代码。
在视图中,
<textarea id="froala-sample-2" ng-init="article.description = article.description || ''" ng-model="article.description"></textarea>
我在file.min.js中将fileUploadToS3更改为true。(as per the docs.)
在角度控制器中
Data.get('{{url}}').then(function(data){
var dta = angular.fromJson(data);
$scope.sign = dta.sign;
$scope.policy = dta.policy;
$scope.bucket = dta.bucket;
$scope.region = dta.region;
$scope.keystart = dta.keystart;
$scope.acl = dta.acl;
$scope.accessKey= dta.key;
$('#froala-sample-2').froalaEditor({
enter: $.FroalaEditor.ENTER_P,
imageUploadToS3: {
bucket: $scope.bucket,
region: $scope.region,
keyStart: $scope.keystart,
params: {
acl: $scope.acl,
AWSAccessKeyId: $scope.accessKey,
policy: $scope.policy,
signature: $scope.sign,
}
}
})
.on('froala.image.uploadedToS3', function (e, editor, link, key, response) {
console.log ('S3 Link:', link);
console.log ('S3 Key:', key);
});}, function (error) {});
这里我创建了签名和政策
public function createSignature() {
// Set date timezone.
date_default_timezone_set('Europe/Bucharest');
$bucket = '-bucket-';
$region = '-region-';
$keyStart = '-keystart-';
$acl = '-acl-';
$accessKeyId = $_SERVER['AWS_ACCESS_KEY'];
$secret = $_SERVER['AWS_SECRET_ACCESS_KEY'];
$policy = base64_encode(
json_encode(
array(
'expiration' => date('Y-m-d\TH:i:s.000\Z', strtotime('+1 day')),
'conditions' => array(
array('bucket' => $bucket),
array('acl' => $acl),
array('success_action_status' => '201'),
array('x-requested-with' => 'xhr'),
array('starts-with', '$key', $keyStart),
array('starts-with', '$Content-Type', '') // accept all files
) )));
$aData['policy'] = $policy;
$aData['sign'] = base64_encode(hash_hmac('sha1', $policy, $secret, true));
$aData['bucket'] = $bucket;
$aData['region'] = $region
$aData['keystart'] = $keyStart;
$aData['acl'] = $acl;
$aData['key'] = $accessKeyId;
return json_encode($aData);}
当我上传图片时,我遇到了以下问题: 选项 https://undefined.amazonaws.com/undefined net :: ERR_NAME_NOT_RESOLVED。 有人请告诉我如何解决这个问题? 提前谢谢。
答案 0 :(得分:1)
确保正确填充imageUploadToS3
个对象:
imageUploadToS3: {
bucket: $scope.bucket,
region: $scope.region,
keyStart: $scope.keystart,
params: {
acl: $scope.acl,
AWSAccessKeyId: $scope.accessKey,
policy: $scope.policy,
signature: $scope.sign,
}
}
从https://undefined.amazonaws.com/undefined错误,我认为至少$scope.bucket
和$scope.region
未定义。
您还可以查看Froala PHP SDK(https://github.com/froala/wysiwyg-editor-php-sdk)及其文档(https://www.froala.com/wysiwyg-editor/docs/sdks/php)SDK将为您执行Amazon S3文件上传。
或者您可以激发创建签名的方式:https://github.com/froala/wysiwyg-editor-php-sdk/blob/master/lib/FroalaEditor/S3.php。以下是有关如何使用它的文档https://www.froala.com/wysiwyg-editor/docs/sdks/php/file-s3-upload。
希望它有所帮助。