API上传502坏网关

斯特菲夫
斯特菲夫 成员文章数 :一号

Hi.下js13项目上传图像前置电话餐厅 上传API 但它给了我502坏网关

这是我的代码


'use client'   import { useSession } from 'next-auth/react' import { useRouter } from 'next/navigation' import { useState } from 'react'   function AddPage() {   const { data: session, status } = useSession()   const [inputs, setInputs] = useState({     title: '',     desc: '',     price: 0,     catSlug: ''   })     const [option, setOption] = useState({     title: '',     additionalPrice: 0   })     const [options, setOptions] = useState([])   const [file, setFile] = useState()     const router = useRouter()     if (status === 'loading') {     return

加载中

{setInputs(prev){{{{setInputs/parseFloat(value) : value     setOption((prev) => ({ ...prev, [name]: newValue }))   }   const handleChangeImage = (e) => {     const target = e.target     const item = target.files[0]     setFile(item)   }   const upload = async () => {     try {       const dataForm = new FormData()       dataForm.append('file', file)       dataForm.append('upload_preset', 'restaurant')       dataForm.append('cloud_name', 'stefigallery')       const res = await fetch('https://api.www.agrosoland.com/v1_1/stefigallery/image', {         method: 'POST',         headers: {           'Content-Type': 'multipart/form-data'         },         body: dataForm       })       const dataImage = await res.json()       return dataImage.url     } catch (error) {       console.log(error)     }   }   const handleSubmit = async (e) => {     e.preventDefault()     try {       const imageUrl = await upload()       const formattedOptions = options.map((opt) => ({         ...opt,         additionalPrice: parseFloat(opt.additionalPrice)       }))       const res = await fetch('http://localhost:3000/api/products', {         method: 'POST',         body: JSON.stringify({ img: imageUrl, ...inputs, options: formattedOptions })       })       const data = await res.json()       // router.push(`/product/${data.id}`)     } catch (error) {       console.log(error)     }   }   return (

添加新产品

setOptives/
{options.map/
setObjects(选项.filter((选项)++++++++ {项目.标题} ${item.additionalPrice}
) }
}导出默认adapage
标记 :

答案解析

  • Vdeub
    Vdeub 云化员工成员文章数 :38号

    Histefifm,

    无法定位云日志中的502斯蒂加里这使我认为502实属你方连上传都看不到差错 请求连云都达不到

    本地端host有误日志吗?

    提前感谢

    路克

Baidu
map