44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Plaintext
		
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Plaintext
		
	
	
import Vue from 'vue'
 | 
						|
import { encoder } from './encoder'
 | 
						|
import { anonymization } from './anonymization'
 | 
						|
export const dcmUpload =  async function(name, file, config){
 | 
						|
  return new Promise(async resolve => {
 | 
						|
    try {
 | 
						|
      // let blob = await encoder(file, config)
 | 
						|
      // let blob = await fileToBlob(file)
 | 
						|
      let blob = await anonymization(file, config)
 | 
						|
      let res = await Vue.prototype.OSSclient.put(name, blob.blob)
 | 
						|
      resolve({
 | 
						|
        ...res,
 | 
						|
        image: blob.pixelDataElement
 | 
						|
      })
 | 
						|
      // let OSSclientA = await OSSclient
 | 
						|
      // let blob = await encoder(file)
 | 
						|
      // let res = await OSSclient.put(name, blob.blob)
 | 
						|
 | 
						|
 | 
						|
    } catch (e) {
 | 
						|
      resolve(false)
 | 
						|
      console.log(e)
 | 
						|
    }
 | 
						|
  })
 | 
						|
}
 | 
						|
function fileToBlob(file) {
 | 
						|
  // 创建 FileReader 对象
 | 
						|
  let reader = new FileReader();
 | 
						|
  return new Promise(resolve => {
 | 
						|
    // FileReader 添加 load 事件
 | 
						|
    reader.addEventListener('load', (e) => {
 | 
						|
      let blob;
 | 
						|
      if (typeof e.target.result === 'object') {
 | 
						|
        blob = new Blob([e.target.result])
 | 
						|
      } else {
 | 
						|
        blob = e.target.result
 | 
						|
      }
 | 
						|
      resolve(blob)
 | 
						|
    })
 | 
						|
    // FileReader 以 ArrayBuffer 格式 读取 File 对象中数据
 | 
						|
    reader.readAsArrayBuffer(file)
 | 
						|
  })
 | 
						|
}
 |