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 (}导出默认adapage
0