【发布时间】:2018-10-25 13:41:19
【问题描述】:
我正在使用 Nativescript 4.2.0 并尝试将图像从本地图像上传到 Azure Blob 存储。
推荐的大多数方法使用 nativescript-background-http 插件。但是,通过包含此插件,开始出现需要其他 npm 模块的错误。我还没有在任何地方看到这个报告,所以我不确定我做错了什么或者旁边还有其他命令可以运行
tns install nativescript-background-http
另一个插件“nativescript-azure-storage”似乎工作正常。这需要我们对我们的图像进行base64编码。 Base64 编码后,图像被上传到 Azure 存储。不过由于图片现在是base64编码的,所以不能直接用在.
使用的代码:
const azureNSStorage = new nsAzureStorage.NativeScriptAzureStorage(config.AZURE_STORAGE_CONNECTION_STRING);
let path = selected.android;
const imageFromLocalFile = imageSourceModule.fromFile(path);
let base64string = imageFromLocalFile.toBase64String('png');
azureNSStorage.uploadBlob(mycontainer, blobName,
base64string)
.then(() => alert(`Uploaded successfuly`))
.catch((err) => alert(`Error uploading: ${err}`));
在 Azure Blob 上上传图像以便我们可以在 Nativescript 页面中引用它们的推荐方法是什么?
干杯 阿布舍克
【问题讨论】:
-
你能分享你收到的错误吗?
标签: azure nativescript