Skip to content

Commit

Permalink
nomadcoders#18.8 Uploading to Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
serranoarevalo committed Jun 27, 2019
1 parent 9e4b32f commit 9cbd591
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"apollo-boost": "^0.4.3",
"apollo-cache-inmemory": "^1.6.2",
"apollo-cache-persist": "^0.1.1",
"axios": "^0.19.0",
"expo": "^33.0.0",
"expo-asset": "^5.0.1",
"expo-camera": "~5.0.1",
Expand Down
29 changes: 25 additions & 4 deletions screens/Photo/UploadPhoto.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState } from "react";
import axios from "axios";
import { Image, ActivityIndicator, Alert } from "react-native";
import styled from "styled-components";
import useInput from "../../hooks/useInput";
import styles from "../../styles";
import constants from "../../constants";
import AuthButton from "../../components/AuthButton";

const View = styled.View`
flex: 1;
Expand Down Expand Up @@ -43,18 +43,39 @@ const Text = styled.Text`
export default ({ navigation }) => {
const [loading, setIsLoading] = useState(false);
const [fileUrl, setFileUrl] = useState("");
const captionInput = useInput("");
const locationInput = useInput("");
const photo = navigation.getParam("photo");
const captionInput = useInput("dfdf");
const locationInput = useInput("dfdfd");
const handleSubmit = async () => {
if (captionInput.value === "" || locationInput.value === "") {
Alert.alert("All fields are required");
}
const formData = new FormData();
const name = photo.filename;
const [, type] = name.split(".");
formData.append("file", {
name,
type: type.toLowerCase(),
uri: photo.uri
});
try {
const {
data: { path }
} = await axios.post("http://localhost:4000/api/upload", formData, {
headers: {
"content-type": "multipart/form-data"
}
});
setFileUrl(path);
} catch (e) {
Alert.alert("Cant upload", "Try later");
}
};
return (
<View>
<Container>
<Image
source={{ uri: navigation.getParam("photo").uri }}
source={{ uri: photo.uri }}
style={{ height: 80, width: 80, marginRight: 30 }}
/>
<Form>
Expand Down
27 changes: 27 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,14 @@ atob@^2.1.1:
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==

axios@^0.19.0:
version "0.19.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8"
integrity sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==
dependencies:
follow-redirects "1.5.10"
is-buffer "^2.0.2"

babel-plugin-module-resolver@^3.1.1:
version "3.2.0"
resolved "https://registry.yarnpkg.com/babel-plugin-module-resolver/-/babel-plugin-module-resolver-3.2.0.tgz#ddfa5e301e3b9aa12d852a9979f18b37881ff5a7"
Expand Down Expand Up @@ -1939,6 +1947,13 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3:
dependencies:
ms "2.0.0"

debug@=3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
dependencies:
ms "2.0.0"

debug@^3.2.6:
version "3.2.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
Expand Down Expand Up @@ -2772,6 +2787,13 @@ find-up@^3.0.0:
dependencies:
locate-path "^3.0.0"

follow-redirects@1.5.10:
version "1.5.10"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
dependencies:
debug "=3.1.0"

fontfaceobserver@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/fontfaceobserver/-/fontfaceobserver-2.1.0.tgz#e2705d293e2c585a6531c2a722905657317a2991"
Expand Down Expand Up @@ -3157,6 +3179,11 @@ is-buffer@^1.1.5:
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==

is-buffer@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725"
integrity sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==

is-data-descriptor@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz#0b5ee648388e2c860282e793f1856fec3f301b56"
Expand Down

0 comments on commit 9cbd591

Please sign in to comment.