([]);
+ const [uploading, setUploading] = useState(false);
+ const [jsonData, setJsonData] = useState({});
+ const [finishedProcessing, setFinishedProcessing] = useState(false);
+
+ const handleUpload = () => {
+ const formData = new FormData();
+ if (invoiceFiles.length > 0) {
+ formData.append('invoice_file', invoiceFiles[0] as FileType);
+ }
+ if (imei1Files.length > 0) {
+ formData.append('imei_files', imei1Files[0] as FileType);
+ }
+ if (imei2Files.length > 0) {
+ formData.append('imei_files', imei2Files[0] as FileType);
+ }
+ formData.append('is_test_request', 'true');
+ setUploading(true);
+ setJsonData({
+ "message": "Please wait..."
+ })
+ const token = localStorage.getItem('sbt-token') || '';
+ fetch(`${baseURL}/ctel/images/process_sync/`, {
+ method: 'POST',
+ body: formData,
+ headers: {
+ "Authorization": `${JSON.parse(token)}`
+ }
+ })
+ .then(async(res) => {
+ const data = await res.json();
+ setJsonData(data);
+ setFinishedProcessing(true);
+ return data;
+ })
+ .then(() => {
+ message.success('Upload successfully.');
+ })
+ .catch(() => {
+ message.error('Upload failed.');
+ })
+ .finally(() => {
+ setUploading(false);
+ });
+ };
+
+ return (
+ <>
+
+
+ {
+ if (finishedProcessing) return;
+ setInvoiceFiles([])
+ }}
+ beforeUpload={(file) => {
+ if (finishedProcessing) return;
+ setInvoiceFiles([file])
+ return false;
+ }}
+ fileList={invoiceFiles}
+ >
+ Invoice File: }>Select Image/PDF
+
+
+
+ {
+ if (finishedProcessing) return;
+ setImei1Files([])
+ }}
+ beforeUpload={(file) => {
+ if (finishedProcessing) return;
+ setImei1Files([file])
+ return false;
+ }}
+ fileList={imei1Files}
+ >
+ IMEI File 1: }>Select Image
+
+
+
+ {
+ if (finishedProcessing) return;
+ setImei2Files([])
+ }}
+ beforeUpload={(file) => {
+ if (finishedProcessing) return;
+ setImei2Files([file])
+ return false;
+ }}
+ fileList={imei2Files}
+ >
+ IMEI File 2: }>Select Image
+
+
+ {!finishedProcessing && }
+ {finishedProcessing && }
+
+
Result:
+
+
+ >
+ );
+};
+
+export default InferencePage;
diff --git a/cope2n-fe/src/request/api.ts b/cope2n-fe/src/request/api.ts
index dbe3a29..a0945df 100644
--- a/cope2n-fe/src/request/api.ts
+++ b/cope2n-fe/src/request/api.ts
@@ -11,18 +11,18 @@ const environment = process.env.NODE_ENV;
const AXIOS_TIMEOUT_MS = 30 * 60 * 1000; // This config sastified long-live upload file request
const EXPIRED_PASSWORD_SIGNAL = 'expired_password';
+export const baseURL = environment === 'development' ? 'http://42.96.42.13:9000/api' : '/api';
+
export const API = axios.create({
timeout: AXIOS_TIMEOUT_MS,
- baseURL:
- environment === 'development' ? 'http://42.96.42.13:9000/api' : '/api',
+ baseURL: baseURL,
maxContentLength: Number.MAX_SAFE_INTEGER,
maxBodyLength: Number.MAX_SAFE_INTEGER,
});
export const PublicAPI = axios.create({
timeout: AXIOS_TIMEOUT_MS,
- baseURL:
- environment === 'development' ? 'http://42.96.42.13:9000/api' : '/api',
+ baseURL: baseURL,
});
// interceptor to handle locale header