Fixed S3 document upload to have minimally functional model
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Upload, Modal, Icon } from "antd";
|
||||
import { Upload, Modal, Icon, Button } from "antd";
|
||||
import axios from "axios";
|
||||
import "./jobs-documents.styles.scss";
|
||||
|
||||
@@ -15,6 +15,8 @@ function getBase64(file) {
|
||||
|
||||
function JobsDetailPage({ match, loading, data }) {
|
||||
//const { jobId } = match.params;
|
||||
|
||||
console.log("match", match);
|
||||
const { t } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
@@ -65,6 +67,23 @@ function JobsDetailPage({ match, loading, data }) {
|
||||
]
|
||||
});
|
||||
|
||||
const test = props => {
|
||||
// axios.get("http://localhost:5000/test").then(r => console.log("r", r));
|
||||
axios({
|
||||
url: "/test",
|
||||
method: "get"
|
||||
})
|
||||
.then(response => {
|
||||
console.log("response", response);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("Payment Error: ", error);
|
||||
alert(
|
||||
"There was an issue with your payment! Please make sure you use the provided credit card."
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const handleUpload = ev => {
|
||||
console.log("Handle Upload.", ev);
|
||||
let file = ev.file;
|
||||
@@ -72,14 +91,17 @@ function JobsDetailPage({ match, loading, data }) {
|
||||
let fileName = ev.file.name;
|
||||
let fileType = ev.file.type;
|
||||
console.log("Preparing the upload ");
|
||||
|
||||
axios
|
||||
.post("http://localhost:5000/sign_s3")
|
||||
.post("/sign_s3", {
|
||||
fileName:
|
||||
"testjob/" + "adcd4c7b-029b-48c7-a1c2-8cf1761ce1dc" + fileName,
|
||||
fileType
|
||||
})
|
||||
.then(response => {
|
||||
var returnData = response.data.data.returnData;
|
||||
var signedRequest = returnData.signedRequest;
|
||||
var url = returnData.url;
|
||||
setState({ url: url });
|
||||
setState({ ...state, url: url });
|
||||
console.log("Recieved a signed request " + signedRequest);
|
||||
|
||||
// Put the fileType in the headers for the upload
|
||||
@@ -91,15 +113,16 @@ function JobsDetailPage({ match, loading, data }) {
|
||||
axios
|
||||
.put(signedRequest, file, options)
|
||||
.then(result => {
|
||||
console.log("Response from s3");
|
||||
this.setState({ success: true });
|
||||
console.log("Response from s3", result);
|
||||
setState({ ...state, success: true });
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("Inside Error here.", error);
|
||||
alert("ERROR " + JSON.stringify(error));
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("Error here.");
|
||||
console.log("Outside Error here.", error);
|
||||
alert(JSON.stringify(error));
|
||||
});
|
||||
};
|
||||
@@ -136,6 +159,7 @@ function JobsDetailPage({ match, loading, data }) {
|
||||
|
||||
return (
|
||||
<div className='clearfix'>
|
||||
<Button onClick={test}>Test</Button>
|
||||
<Upload
|
||||
customRequest={handleUpload}
|
||||
accept='.pdf,.jpg,.jpeg'
|
||||
|
||||
Reference in New Issue
Block a user