问题描述
我想在 kartik 文件输入中显示我在 AWS S3 中托管的文件的预览。
我正在获取 aws s3 文件的预签名 uri,因为如果没有,当我尝试加载文件预览时,aws 会返回 403
错误。
$credentials = new Aws\Credentials\Credentials($awsAccessId,$awsSecretKey);
$s3 = new Aws\S3\S3Client([
'credentials' => $credentials,'version' => 'latest','region' => 'eu-central-1','retries' => 0
]);
if ($s3){
try {
$cmd = $s3->getCommand('Getobject',[
'Bucket' => $awsBucket,'Key' => $s3_key,'retries' => 0
]);
$request = $s3->createPresignedRequest($cmd,'+20 minutes');
$url_aws = (string)$request->getUri();
} catch (S3Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
$(document).ready(function(){
var aws_url = [];
aws_url[0] = "<?PHP echo $url_aws ?>";
$("#archivo").fileinput({
language: '<?PHP echo $fileInputLang ?>',showUpload: false,showRemove: false,showClose: false,browSEOnZoneClick: true,overwriteInitial: false,initialPreview: aws_url,initialPreviewAsData: true,// identify if you are sending preview data only and not the raw markup
// initialPreviewFileType: 'image',// image is the default and can be overridden in config below
// initialPreviewDownloadUrl: 'https://kartik-v.github.io/bootstrap-fileinput-samples/samples/{filename}',// includes the dynamic `filename` tag to be replaced for each config
initialPreviewConfig: [
{type: "pdf",size: 8000,caption: "<?PHP echo $nombre ?>",url: false,downloadUrl: false}
],initialPreviewShowDelete: false,});
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)