upd: upload file

This commit is contained in:
amel
2024-09-11 16:46:45 +08:00
parent 57c245a880
commit 5ee3cb791c
7 changed files with 80 additions and 43 deletions

View File

@@ -3,11 +3,9 @@ import createLogUser from "./log/fun/createLogUser";
import { funGetAllmember } from './member/lib/api_member';
import Profile from './profile/ui/profile';
import EditProfile from './profile/ui/edit_profile';
import { fileUpload } from './profile/lib/upload_img_profile';
export { createLogUser };
export type { TypeUser }
export { funGetAllmember }
export { Profile }
export { EditProfile }
export { fileUpload }
export { EditProfile }

View File

@@ -1,27 +0,0 @@
export async function fileUpload({ file }: { file: File}) {
const formData = new FormData();
formData.append("file", file);
formData.append("dirId", "cm0x8dbwn0005bp5tgmfcthzw");
try {
const res = await fetch("https://wibu-storage.wibudev.com/api/upload", {
method: "POST",
body: formData,
headers: {
Authorization: `Bearer ${process.env.WS_APIKEY}`
}
});
if (res.ok) {
console.log("File uploaded successfullyAmalia");
const hasil = await res.text()
console.log('berhasilAmalia',hasil)
} else {
const errorText = await res.text();
console.log('errorAmalia',errorText)
}
} catch (error) {
console.error("Upload error:", error);
}
}

View File

@@ -28,6 +28,7 @@ export default function Profile() {
const res = await funGetProfileByCookies()
setData(res.data)
setIMG(`/api/file/img?jenis=image&cat=user&file=${res.data.img}`)
// setIMG(`https://wibu-storage.wibudev.com/api/files/view/cm0x8dbwn0005bp5tgmfcthzw/${res.data.img}`)
setLoading(false)
} catch (error) {
console.error(error);