| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import getSize from '../3rd-libs/filesize';
- /**
- * 获取文件的尺寸
- */
- export const getFileSize = getSize;
- /**
- * 将URL转换为blob数据
- * @param {string} url - 地址
- */
- export async function url2Blob(url) {
- try {
- // 使用 fetch 获取资源
- const response = await fetch(url);
- // 检查响应是否成功(状态码在 200-299 之间)
- if (!response.ok) {
- throw new Error(`Network response was not ok: ${response.statusText}`);
- }
- // 将响应转换为 Blob 对象
- const blob = await response.blob();
- return blob;
- } catch (error) {
- console.error('There was a problem with the fetch operation:', error);
- throw error;
- }
- }
- /**
- * 根据文件名获取文件后缀名
- * @param {string} file_name
- * @returns
- */
- export const getFileSuffix = (file_name) => {
- if (!file_name) {
- return '';
- }
- const name_info_arr = file_name.split('.');
- const end_fix = name_info_arr[name_info_arr.length - 1];
- return end_fix;
- };
|