加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 如何使用cordova api将照片上传到azure blob存储?

发布时间:2020-12-17 07:27:15 所属栏目:安全 来源:网络整理
导读:我正在尝试使用Cordova api将照片从移动设备上传到azure blob存储.我似乎无法让它工作.任何想法都会有很大帮助. 上传到blob的数据如下所示. start —- –+++++org.apache.cordova.formBoundary Content-Disposition: form-data; name=”file”; filename=”t
我正在尝试使用Cordova api将照片从移动设备上传到azure blob存储.我似乎无法让它工作.任何想法都会有很大帮助.

上传到blob的数据如下所示.

start —->

–+++++org.apache.cordova.formBoundary

Content-Disposition: form-data; name=”file”; filename=”test”

Content-Type: image/jpeg

Content-Length: 46785

???? ….

<— end

我的代码:

/*Cordova Camera API calls*/
$scope.takePic = function (type) {

    if (navigator.camera != undefined) {
        if (type == 'PHOTOLIBRARY')
            type = Camera.PictureSourceType.PHOTOLIBRARY;
        else if (type == 'CAMERA')
            type = Camera.PictureSourceType.CAMERA;

        var options = {
            quality: 45,destinationType: Camera.DestinationType.DATA_URL,sourceType: type,allowEdit: true,encodingType: Camera.EncodingType.JPEG,saveToPhotoAlbum: false
        }
        navigator.camera.getPicture(onSuccess,onFail,options); 
    }
}

$scope.message = "Add an image";
var onSuccess = function (DATA_URL) {
    $scope.message = "Choose another image"; 
    $scope.postForm.onFileSelect = DATA_URL;
    $scope.$apply();
};
var onFail = function (e) {
    $scope.picData = null; 
    $scope.message = "On fail " + e;
};

//$scope.blobSasUrl is url to upload to azure blob storage
var xhr = new XMLHttpRequest();
xhr.onerror = fail;
xhr.onloadend = uploadCompleted;
xhr.open("PUT",$scope.blobSasUrl);
xhr.setRequestHeader('x-ms-blob-type','BlockBlob');
xhr.setRequestHeader('x-ms-blob-content-type','image/jpeg');
xhr.send($scope.postForm.onFileSelect);

编辑 – – –
//我正在使用Camera.DestinationType.DATA_URI.我也尝试过FILE_URI.

//This is not working (error)
var reader = new FileReader();
reader.onloadend = function(evt) {
    console.log(evt.target.result);  //nothing happens here
}
reader.readAsDataURL(file);  //file is either DATA_URI or FILE_URI
在您的azure帐户上创建blob存储服务,将blob存储库导入您的网站.将图像发送到Azure上托管的网站,然后分离任务以将其发送到blob存储.您使用Cordova作为客户端这一事实无关紧要.服务器不应该知道平台客户端是谁,只是如何处理请求.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读