oss blob上传

// const OSS = require('ali-oss');

// const client = new OSS({
// region: 'oss-cn-hangzhou',
// accessKeyId: 'LTAIBZRs7kInJQzY',
// accessKeySecret: '0Rt1TZpc6rvyIopixD1hjJdCheZgnH',
// bucket: 'ekokucqz'
// });

  

 //上传附件oss
    attachmentsUpload = (listName,option) => {
      // const ossName = option.file.name.split(".")[0];
      const date = `${new Date().getFullYear()}${new Date().getMonth()}${new Date().getDate()}`;
      const ossKey = "file/"+date+"/"+new Date() * 1+"/"+option.file.name;
      //上传进度条显示
      // client.multipartUpload(ossKey, option.file , {
      //   async progress(percentage) {
      //     option.onProgress({ percent: percentage*100});
      //   }
      // }).then((result)=>{
      //   // console.log(result);
      //   let data = {
      //     code:"200",
      //     data:{id:result.name,name:option.file.name,url:result.res.requestUrls[0].split("?")[0]},
      //     success:true
      //   };
      //   // option.onProgress({ percent: 100 });
      //   option.onSuccess(data);
      // }).catch(function (err) {

      // });
      let disableds = {...this.state};
      disableds["disabled"+listName] = true;
      this.setState(disableds);
      blobService.createBlockBlobFromBrowserFile(BlobName, 
      ossKey, 
      option.file, 
      (error, result) => {
          if(error) {
              // Handle blob error
              let stateData = {...this.state};
              stateData[listName] = stateData[listName] - 1;
              this.setState(stateData, () => {
                if(this.state[listName] === 0){
                    let disState = {...this.state};
                    disState["disabled"+listName] = false;
                    this.setState(disState);
                }
              });
          } else {
              let stateData = {...this.state};
              // console.log(result);
              let data = {
                  id:result.name,
                  uid:result.name,
                  name:option.file.name,
                  url:`https://${AccountName}.blob.core.chinacloudapi.cn/${BlobName}/${result.name}`,
                  status:'done',
              };
              stateData.PhotosList[listName+"List"].push(data);
              stateData["required"+listName] = false;
              stateData[listName] = stateData[listName] - 1;
              this.setState(stateData, () => {
                if(this.state[listName] === 0){
                    let disState = {...this.state};
                    disState["disabled"+listName] = false;
                    this.setState(disState);
                }
              });
          }
      });
import AzureStorage from './azure-storage.blob.min.js';
const blobUri = `https://${account.name}.blob.core.chinacloudapi.cn`;
const blobService = AzureStorage.createBlobServiceWithSas(blobUri, account.sas);
window.blobService = blobService;
window.BlobName = ""
window.AccountName = ""

猜你喜欢

转载自www.cnblogs.com/guidan/p/9812145.html