#鸿蒙通关秘籍#如何实现HarmonyOS NEXT中的照片上传与处理

HarmonyOS
2024-12-02 14:55:07
542浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
SKU风翼

要实现照片上传,创建一个处理选中过照片的函数,并将其上传到服务器:

import { uploadImg } from '../api/User';

function uploadPhoto(filePath) {
  const formData = new FormData();
  formData.append('file', filePath);

  const config = {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    context: context,
  };

  uploadImg(formData, config).then((response) => {
    if (response.data && response.data.url) {
      console.log('Photo uploaded successfully.', response.data.url);
    }
  }).catch((error) => {
    console.error('Failed to upload photo.', error);
  });
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
分享
微博
QQ
微信
回复
2024-12-02 16:22:42


相关问题