Socket
Socket
Sign inDemoInstall

qw-oss

Package Overview
Dependencies
12
Maintainers
0
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

qw-oss

> TODO: description


Version published
Weekly downloads
79
increased by338.89%
Maintainers
0
Created
Weekly downloads
 

Readme

Source

## OSS 上传公共组件-链接阿里 oss

\1. 引入
import QwOss from 'qw-oss'
\2. 初始化
// 调用接口初始化 oss

const initOss = async () => {
  QwOss.install({ fetchOssInfo: '后端返回 oss 配置的接口/promise 配置对象' })

  QwOss.reinstall()
}
\3. 上传
// 上传文件

   const uploadFile = async (file: File, { chunked = false, maxSize = 3 }): Promise<IUploadFile *|* *null*> => 	{

   		console.log('开始上传---->', file)
			// 检查是否初始化 oss

			await initOss()

			console.log('初始化完成')
			try {

						if (!file) {

								throw new Error('No file selected')

						}

			const resultFile = await QwOss.upload(file, {

			onProgress: (num) => {

					setProgress(num)

			}

		})

		setResultFile({

				fileName: file.name,

				name: resultFile.name,

				url: resultFile.name

		})

		const uploadResult = {

				fileName: file.name,

				name: resultFile.name,

				url: resultFile.name

		}

		setUploaded(true)

		return uploadResult

	} catch (err) {

			setError(err.message)

			Message.error(err.message || '上传失败!')

	}

}

FAQs

Last updated on 27 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc