帖子
帖子
用户
博客
课程
0
帖子
0
勋章
60
Y币
感觉很赞。
2
帖子
0
勋章
17
Y币
我要金币,
45
帖子
0
勋章
411
Y币
网络延迟会出现部分图片上传丢失的情况
22
帖子
0
勋章
140
Y币
没看懂,这是在干嘛哦?
22
帖子
0
勋章
140
Y币
老邮局 发表于 2015-4-27 19:31
又一阵风,带有颜色的给力的风

颜色咋弄的
0
帖子
0
勋章
20
Y币
先拍照预览,再上传
45
帖子
0
勋章
411
Y币
早就没了吧
0
帖子
0
勋章
26
Y币
我好像会
0
帖子
0
勋章
15
Y币
谢谢分享
2
帖子
0
勋章
703
Y币
  1.                var model = api.require('model');
  2.                model.uploadFile({
  3.                    report: false,
  4.                    data: {
  5.                        file: {
  6.                            name: 'avatar.'+fileType,
  7.                            url: locAvatar
  8.                        }
  9.                    }
  10.                }, function(ret, err){
  11.                    if( ret ){
  12.                         console.log( JSON.stringify( ret ));
  13.                         fnPost('user/'+userId, {
  14.                             body:JSON.stringify({
  15.                                   avatar:ret,
  16.                                   city:locCity,
  17.                                   birthday:locBirthday,
  18.                                   gender:locGender,
  19.                                   _method:'PUT'
  20.                                })
  21.                         }, 'application/json', true, true, function(ret, err) {
  22.                             if (err) {
  23.                               api.alert({
  24.                                   title: '提示',
  25.                                   msg: JSON.stringify(err)
  26.                               });
  27.                             } else {
  28.                               console.log(JSON.stringify(ret));
  29.                             }
  30.                         });
  31.                    }else{
  32.                         console.log( JSON.stringify( err ) );
  33.                    }
  34.                });



  35. function fnPost(path, data, contentType, isLogin, isPut, callback) {
  36.      var headers = {
  37.          "X-APICloud-AppId": appid,
  38.          "X-APICloud-AppKey": appKey
  39.      };

  40.      if (contentType) {
  41.          headers["Content-Type"] = contentType
  42.      }

  43.      var accessToken = $api.getStorage('accessToken');

  44.      if(accessToken){
  45.          headers["authorization"] = accessToken;
  46.      }

  47.      if (isLogin) {
  48.          if (!accessToken) {
  49.              api.openWin({
  50.                  name: 'login',
  51.                  url: 'widget://html/login.html'
  52.              });
  53.              return;
  54.          }
  55.      }

  56.      api.showProgress({
  57.          title: '拼命加载中...',
  58.          modal: false
  59.      });

  60.     //  alert(JSON.stringify(headers))
  61.     console.log('Path:'+'https://d.apicloud.com/mcm/api/' + path + 'Data:' + JSON.stringify(data));
  62.      api.ajax({
  63.          url: 'https://d.apicloud.com/mcm/api/' + path,
  64.          method: isPut ? 'put' : 'post',
  65.          timeout: 60,
  66.          dataType: 'json',
  67.          returnAll: false,
  68.          headers: headers,
  69.          cache: false,
  70.          data: data
  71.      }, function(ret, err) {
  72.          api.refreshHeaderLoadDone();
  73.          api.hideProgress();
  74.          callback(ret, err);
  75.      });
  76. };
复制代码


这种方法可以。
您需要登录后才可以回帖 登录

本版积分规则