/**上传图片*/
import {putFileFun} from '@/api/resource/oss';
import compress from '@/util/compress';

export default ({file, onProgress, onError, onSuccess}) => {
  onProgress({percent: 0});
  compress(file, 300)
      .then(({compressedFile}) => {
        putFileFun(
            compressedFile,
            (progressEvent) => {
              let complete =
                  ((progressEvent.loaded / progressEvent.total) * 100) | 0;
              onProgress({percent: complete});
            })
            .then((res) => {
              onSuccess(res.data, compressedFile);
            })
            .catch(onError);
      })
      .catch(onError);
}