upload images
This commit is contained in:
@@ -1,17 +1,7 @@
|
||||
import * as ImagePicker from "expo-image-picker";
|
||||
import * as Minio from "minio";
|
||||
import { useState } from "react";
|
||||
import { ActivityIndicator, Button, Image, StyleSheet, Text, TextInput, View } from "react-native";
|
||||
|
||||
const minioClient = new Minio.Client({
|
||||
endPoint: "content2.reversed.dev",
|
||||
port: 443,
|
||||
useSSL: true,
|
||||
accessKey: "tv-control",
|
||||
secretKey: "0gEjOlnVAECrqJx5Nd77y7Hhouc5faVf0WttjcRH",
|
||||
});
|
||||
|
||||
const bucket = "tv-control";
|
||||
const BASE_URL =
|
||||
"https://shsf-api.reversed.dev/api/exec/15/1c44d8b5-4065-4a54-b259-748561021329";
|
||||
|
||||
@@ -67,6 +57,7 @@ export function IndexPage() {
|
||||
const result = await ImagePicker.launchCameraAsync({
|
||||
mediaTypes: "images",
|
||||
quality: 0.8,
|
||||
base64: true,
|
||||
});
|
||||
|
||||
if (result.canceled) return;
|
||||
@@ -76,31 +67,14 @@ export function IndexPage() {
|
||||
setUploading(true);
|
||||
|
||||
try {
|
||||
const fileName = `tv-image-${Date.now()}.jpg`;
|
||||
|
||||
// Get a presigned URL for PUT upload (pure signing — no HTTP call)
|
||||
const presignedUrl = await minioClient.presignedPutObject(
|
||||
bucket,
|
||||
fileName,
|
||||
60 * 60
|
||||
);
|
||||
|
||||
// Upload the image blob using native fetch
|
||||
const blob = await fetch(asset.uri).then((r) => r.blob());
|
||||
await fetch(presignedUrl, {
|
||||
method: "PUT",
|
||||
body: blob,
|
||||
headers: { "Content-Type": "image/jpeg" },
|
||||
});
|
||||
|
||||
const imageUrl = `https://content2.reversed.dev/${bucket}/${fileName}`;
|
||||
|
||||
// Push the public URL to the server
|
||||
await fetch(`${BASE_URL}/push_image_url`, {
|
||||
// Send base64 image to server — server uploads to Minio and saves the URL
|
||||
const res = await fetch(`${BASE_URL}/push_image`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ image_url: imageUrl }),
|
||||
body: JSON.stringify({ image_b64: asset.base64 }),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.status !== "success") throw new Error(data.message ?? "Upload failed");
|
||||
|
||||
alert("Image uploaded and sent to TV!");
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user