首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cordova-plugin-file不上传cdvfile:// path到服务器

cordova-plugin-file不上传cdvfile:// path到服务器
EN

Stack Overflow用户
提问于 2022-06-28 17:07:47
回答 1查看 156关注 0票数 -2

可以肯定,在将文件从本地路径传输到远程服务器时,不再需要cordova-plugin-file-transfer

我能够获得cdvfile://路径,甚至可以在DOM上显示相同的路径,但是我不知道如何仅仅使用文件插件而不是文件传输来上传它。

到目前为止这是我的密码。我使用了插件:

  • cordova-plugin-camera
  • cordova-plugin-file
  • cordova-plugin-crop

代码:

代码语言:javascript
复制
function clickFirstProfilePhoto(){

    navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
    correctOrientation:true, 
    targetWidth:1024, 
    targetHeight: 1024, 
    destinationType: 
    destinationType.FILE_URI});
}  

现在成功的功能:

代码语言:javascript
复制
function onPhotoDataSuccess(imageData) {
           
plugins.crop.promise(imageData).then(function success (imageFinal) {
          // Success.
          //alert(imageFinal);
          var fileURI = imageFinal.substr(imageFinal.lastIndexOf('?') + 1);
          //alert(fileURI);
          resolveLocalFileSystemURL(imageFinal, function(entry) {
          $("#picPreviewBox").html('<img src="'+entry.toInternalURL()+'" width="100%" />');

            var t=""
            t=t+'<div class="btn btn-dark btn-sm">Save</div> <div class="btn btn-dark btn-sm">discard</div>';
            $("#buttons_save_discard").html(t);

            
          });


}).catch(function fail (err) {
          // fail
 $.alert("Seems your phone resources are too low to proceed further");
        });

 }

在DOM中使用entry.toInternalURL()显示所捕获的图片,然后裁剪图片,但是如何将其与一些参数一起上传到服务器上的url?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-04 10:36:39

好的,我现在有了解决办法。获取文件路径后,我将其转换为base64,然后将其上传到服务器上的PHP中,以便将其保存为图像,下面是代码:

代码语言:javascript
复制
    function onPhotoDataSuccess(imageData) {
               
    plugins.crop.promise(imageData).then(function success (imageFinal) {
              // Success.
              //alert(imageFinal);
              var fileURI = imageFinal.substr(imageFinal.lastIndexOf('?') + 1);
              //alert(fileURI);
              resolveLocalFileSystemURL(imageFinal, function(entry) {
                
                $("#loadSignup3Data").html('<img src="'+entry.toInternalURL()+'" id="imagePreviewBox" width="200p" height="200" style="border-radius:50%;" />');
               // $("#picPreview").modal('show');
                $("#picOptions").modal('hide');
                $("#picPreviewBox").html('<img src="'+entry.toInternalURL()+'" id="imagePreviewBox" width="200p" height="200"/>');
                //$("#picPreview").modal('show');
               $.confirm({
                title: 'Please confirm!',
                content: 'Do you wish to save it as your profile picture?',
                buttons: {
                    confirm: function () {
                        
                        $("#ultraLoader").show();
                        html2canvas(document.querySelector("#imagePreviewBox")).then(canvas => {
                            var renderedImg = canvas.toDataURL();
                            var id = $("#pictureUploadID").val();
                            var deviceid = device.uuid;
                          
          $.ajax({
          type: "POST",
          url: "https://my_url_which_i_must_not_show/saveFirstProfilePic.php",
          dataType:'json',
          data: {base64Img: renderedImg, id:id, deviceid:deviceid},
          success: function(response){
             $("#ultraLoader").hide();
             $.alert("Your profile picture has been saved");
             location.href = "Dashboard.html?id="+id;
             }
            });

          });
             
   },cancel: function () {
    navigator.notification.alert('You chose not to save the picture. Please take another picture or select one from your phone gallery');
       $("#ultraLoader").hide();
                 }
                }
            });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72790607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档