我们在vue.js应用程序中使用axios来访问Azure功能.现在我们收到这个错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:8080' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)
我们试图以这种方式在函数中设置响应头:
context.res = {
body: response.data,
headers: {
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Origin': 'http://localhost:8080',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Request-Headers': 'X-Custom-Header'
}
}
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过这个错误?
目标:使用文件资源管理器选择文件并上传到 Firebase 存储。
包:file_picker:^2.1.4
问题:引发错误:“无效参数(路径):不得为空”。
文件资源管理器打开正常,我可以选择一个文件。但是,选择文件后没有任何反应。下面是我迄今为止尝试过的代码:
FilePickerResult result;
File uploadfile;
try{
result = await FilePicker.platform.pickFiles(type: FileType.custom,
allowedExtensions: ['jpg', 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'txt'],
);
} catch(e) {
print(e);
}
if(result != null) {
try{
uploadfile = File(result.files.single.path);
String filename = basename(uploadfile.path);
StorageReference storageRef = FirebaseStorage.instance.ref().child('$path$filename');
final StorageUploadTask uploadTask = storageRef.putFile(uploadfile);
final StorageTaskSnapshot downloadUrl = (await uploadTask.onComplete);
if (downloadUrl.error == null){
final String attchurl = (await downloadUrl.ref.getDownloadURL());
}
} catch(e) {
print(e);
}
Run Code Online (Sandbox Code Playgroud)
我确信代码会在以下位置引发错误:uploadfile = File(result.files.single.path);
我尝试了多个博客中提供的各种建议。即使这里的解决方案没有帮助,我也遇到同样的错误。参见下面的代码: …