使用Tymon令牌作为auth。拉勒维尔工作得很好。
当使用用于Laravel蒸气的上载到S3代码时,我无法获得已签名的存储-url来使用我的axios默认值:
axios.defaults.headers.common["Authorization"] = 'Bearer ' + token;
存储方法,如文档中所示:
Vapor.store(this.$refs.file.files[0], {
progress: progress => {
this.uploadProgress = Math.round(progress * 100);
}
}).then(response => {
...它在npm包的index.js中将此称为:
async store(file, options = null) {
// want this to use my default header.
const response = await axios.post('/vapor/signed-storage-url', {
'bucket': options.bucket || '',
'content_type': options.contentType || file.type,
'expires': options.expires || ''
});也许是因为npm模块没有在正确的范围内。
我已经重写了蒸气核心签名存储url控制器来使用令牌,并且可以让它与邮递员一起工作。调用Vapor.store没有将令牌添加到axios调用中,而且我没有看到传递标头的方法。
编辑:您可以不用注册Vapor就可以使用这些包。
composer require laravel/vapor-core和
npm install --save-dev laravel-vapor发布于 2019-10-25 05:58:43
解决了问题,因此为了完成这项工作,我将异步存储方法复制到vue组件方法中,并从那里调用它。获取默认标题,但是..。
这在S3中创建了一个axios头问题,通过这样做解决了这个问题:
async store(file, options = null) {
const response = await axios.post('/vapor/signed-storage-url', {
'bucket': options.bucket || '',
'content_type': options.contentType || file.type,
'expires': options.expires || ''
});
if (typeof options.progress === 'undefined') {
options.progress = () => {};
}
// This is the fix for the headers. Instance just for the S3 PUT
var instance = axios.create();
instance.defaults.headers.common = {};
const s3Response = await instance.put(response.data.url, file, {
headers: response.data.headers,
onUploadProgress: (progressEvent) => {
options.progress(progressEvent.loaded / progressEvent.total);
}
});
response.data.extension = file.name.split('.').pop()
return response.data;
},多亏了https://github.com/axios/axios/issues/382#issuecomment-254712154
https://stackoverflow.com/questions/58493339
复制相似问题