2017-02-21 2 views
0

Momentan integriere ich froala in mein Projekt (welches in angualarJs und laravel ist). Ich muss das Bild auf amazonS3 hochladen. Aber ich habe ein paar Probleme mit dem AmazonS3-Pfad. Hier ist mein Code.Bild zu amazonS3 Problem hochladen Froala

mit in der Ansicht,

<textarea id="froala-sample-2" ng-init="article.description = article.description || ''" ng-model="article.description"></textarea> 

änderte ich die fileUploadToS3 auf wahr in file.min.js. (as per the docs.)

mit dem Winkelregler

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) {}); 

hier IAM Erstellen der Unterschrift und der Richtlinie

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);} 

Wenn ich ein Bild hochladen, bekam ich die folgende Frage: OPTIONS https://undefined.amazonaws.com/undefined net :: ERR_NAME_NOT_RESOLVED. Jemand bitte sagen Sie mir, wie kann ich dieses Problem lösen? Vielen Dank im Voraus.

Antwort

1

Stellen Sie sicher, dass imageUploadToS3 Objekt korrekt ausgefüllt ist:

imageUploadToS3: { 
    bucket: $scope.bucket, 
    region: $scope.region, 
    keyStart: $scope.keystart, 
    params: { 
    acl: $scope.acl, 
    AWSAccessKeyId: $scope.accessKey, 
    policy: $scope.policy, 
    signature: $scope.sign, 
    } 
} 

Von https://undefined.amazonaws.com/undefined Fehler, Ich gehe davon aus, dass zumindest $scope.bucket und $scope.region nicht definiert sind.

Sie können auch Froala PHP SDK (https://github.com/froala/wysiwyg-editor-php-sdk) und seine Dokumentation (https://www.froala.com/wysiwyg-editor/docs/sdks/php) überprüfen Das SDK wird die Amazon S3-Datei hochladen für Sie.

Oder Sie können inspirieren, wie die Signatur erstellt wird: . Und hier ist die Dokumentation, wie man es benutzt https://www.froala.com/wysiwyg-editor/docs/sdks/php/file-s3-upload.

Ich hoffe, es hilft.