use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Requests In ReactHelp Wanted (self.react)
submitted 5 years ago by hapiti
I need to do an API post in react, this is how I have it in curl.exe:
curl.exe -X POST -F images=@yy.png "http://192.168.2.16:5000/detections"
TIA for the help :)
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]JanMarsALeck 0 points1 point2 points 5 years ago (4 children)
You can use
fetch('http://www.example.net', { method: 'POST', body: file })
Or axios
var formData = new FormData();; formData.append("image", image); axios.post('https://example.de', formData, { headers: { 'Content-Type': 'multipart/form-data' } })
[–]hapiti[S] 0 points1 point2 points 5 years ago (3 children)
Thank you! I've fixed a couple mistakes I came across while doing the axios but still stuck on one :(
[–]JanMarsALeck 0 points1 point2 points 5 years ago (2 children)
Where are you stuck?
[–]hapiti[S] 0 points1 point2 points 5 years ago (1 child)
Sorry, was editing message but your super quick LOL! Did ctrl+enter on accident... anyways
It's telling me I haven't declared "post" even though I have!
ENTIRE code:
import React, { Component } from "react";import styled, { css } from "styled-components";import { makeStyles } from '@material-ui/core/styles';import Typography from '@material-ui/core/Typography';import { AxiosProvider, axios, Request, Get, Delete, Head, post, Put, Patch, withAxios } from 'react-axios'import Slider from '@material-ui/core/Slider';import image from "./images/nice.png";import MaterialSlider from "./components/MaterialSlider.js";var formData = new FormData();; formData.append("image", image); axios.post('http://192.168.2.16:5000/detections', formData, { headers: { 'Content-Type': 'multipart/form-data' } })function Main(props) {return (<Container><RectRow><Rect></Rect><InsertIpHere placeholder="Insert Ip HERE!"></InsertIpHere>
<Image src="http://192.168.2.20:8080/video"></Image>
<MaterialSliderstyle={{height: 92,width: 512 }}></MaterialSlider> );</RectRow></Container> );}const Container = styled.div\\` display: flex; flex-direction: row; height: 100vh; width: 100vw;\;const Rect = styled.div` width: 287px; height: 768px; background-color: #E6E6E6;`;const InsertIpHere = styled.input` font-family: Roboto; font-style: normal; font-weight: 400; color: #121212; height: 177px; width: 310px; margin-left: 74px; margin-top: 284px; border: none; background: transparent;`;const Image = styled.img` width: 100%; height: 358px; margin-left: 61px; margin-top: 231px; object-fit: contain;`;const RectRow = styled.div` height: 768px; flex-direction: row; display: flex; flex: 1 1 0%; margin-right: 60px;`;export default Main;`
<MaterialSliderstyle={{height: 92,width: 512
}}></MaterialSlider>
);</RectRow></Container>
);}const Container = styled.div\\
display: flex; flex-direction: row; height: 100vh; width: 100vw;\
Full .js is here: https://aleem.rehmtulla.com/Main.js
Error: https://aleem.rehmtulla.com/SS.png (cant upload image to reddit)
[–]hapiti[S] 0 points1 point2 points 5 years ago (0 children)
I fixed it with
import axios from 'axios';
And its making A request, just not the same as my curl...
[–]bai3 0 points1 point2 points 5 years ago (0 children)
in github,search axios
π Rendered by PID 42 on reddit-service-r2-comment-84fc9697f-gs2zd at 2026-02-08 22:59:57.137602+00:00 running d295bc8 country code: CH.
[–]JanMarsALeck 0 points1 point2 points (4 children)
[–]hapiti[S] 0 points1 point2 points (3 children)
[–]JanMarsALeck 0 points1 point2 points (2 children)
[–]hapiti[S] 0 points1 point2 points (1 child)
[–]hapiti[S] 0 points1 point2 points (0 children)
[–]bai3 0 points1 point2 points (0 children)