Ionic React 및 Capacitor 카메라를 사용한 Supabase 스토리지 이미지 업로드 튜토리얼
6659 단어 reactjavascriptionicsupabase
비디오
카메라 이미지 업로드
모든 마법은 여기서 일어난다
/**
* upload to storage bucket, convert path to blob
* get file name from path
*
* @param path
*/
const uploadImage = async (path: string) => {
const response = await fetch(path);
const blob = await response.blob();
const filename = path.substr(path.lastIndexOf("/") + 1);
const { data, error } = await supabase.storage
.from("image-bucket")
.upload(`${filename}`, blob, {
cacheControl: "3600",
upsert: false,
});
if (error) alert(error?.message);
console.log(data);
getAllImages();
return true;
};
Capacitor Camera Plugin에서
webPath
를 가져오고 fetch
를 사용하여 blob을 얻은 다음 supabase에 업로드합니다.Supabase에서 이미지 다운로드
여기서 내가 하는 일은 별도의 구성 요소
RenderImage
를 만들고 초기useEffect
후크에서 supabase에 대한 API 호출을 만들어 이미지의 publicURL을 가져오고 변수가 설정되면 로컬 상태 변수로 설정합니다. 이미지가 화면에 그려집니다.const RenderImage: React.FC<any> = ({ path }) => {
const [publicUrl, setPublicUrl] = useState<any>("");
useEffect(() => {
(async () => {
const { publicURL } = supabase.storage
.from("image-bucket")
.getPublicUrl(path);
setPublicUrl(publicURL);
})();
},[path]);
return <IonImg src={publicUrl} />;
};
나머지는 모두...
비디오의 나머지 부분은 supabase api와 사용을 위해 버킷을 설정하는 방법에 대한 자세한 설명입니다.
소스 코드
Reference
이 문제에 관하여(Ionic React 및 Capacitor 카메라를 사용한 Supabase 스토리지 이미지 업로드 튜토리얼), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/aaronksaunders/supabase-storage-image-upload-tutorial-using-ionic-react-capacitor-camera-2ob2텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)