0

I am trying to send my Form data to server on base of API, but every time I click on the upload button, it gives me this error:

Localhost 404 Not Found

How can I figure out if there is any mistake in my code?

I will also share code snippet of my Form. I used ant-design for Form and Upload.

Code Snippet

import React from 'react';
import styled from 'styled-components';
import 'antd/dist/antd.css';
import { Form, Upload, message, Button, Icon } from 'antd';
import reqwest from 'reqwest';

const FormItem = Form.Item;
const PhotoText = styled.div`
  font-size: 16px;
  font-weight: bold;
  padding: 2rem 0 1rem 0;
  display: block;
  text-align: -webkit-auto;
`;

class RegisterStepTwo extends React.Component {
  constructor(props) {
    super(props);
    console.log(props);
  }
  handleUpload = e => {
    // You can use any AJAX library you like
    console.log(e.file.originFileObj);
    var reader = new FileReader();
    var obj = JSON.parse(localStorage.getItem('user'));

    reader.onload = function(upload) {
      const userOject = {
        ...obj,
        uri: upload.target.result,
      };
      reqwest({
        url: fetch(`http://138.197.207.41:9000/api/s3/uploadtoawsapi`, {
          headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
          },
          method: 'POST',
          body: JSON.stringify({
            userId:userObject,
            type,
            content,
            key,
            oldKey,
          }),
        }),
        success: () => {
          message.success('upload successfully.');
        },
        error: () => {
          message.error('upload failed.');
        },
      });
    };
    reader.readAsDataURL(e.file.originFileObj);
  };

  render() {
    const { getFieldDecorator } = this.props;
    return (
      <div>
        <PhotoText>Select a Photo to Upload</PhotoText>

        <Form onSubmit={this.handleSubmit}>
          <FormItem>
            {getFieldDecorator('picture', {
              rules: [
                {
                  required: true,
                  message: 'Please upload picture!',
                },
              ],
            })(
              <Upload>
                <Button>
                  <Icon type="upload" /> Click to Upload
                </Button>
              </Upload>,
            )}
          </FormItem>

          <PhotoText>Select a Video to Upload</PhotoText>
          <FormItem>
            {getFieldDecorator('video', {
              rules: [
                {
                  required: true,
                  message: 'Please upload video!',
                },
              ],
            })(
              <Upload>
                <Button>
                  <Icon type="upload" /> Click to Upload
                </Button>
              </Upload>,
            )}
          </FormItem>
        </Form>
      </div>
    );
  }
}
export default RegisterStepTwo;
halfer
  • 19,824
  • 17
  • 99
  • 186
Brad
  • 123
  • 3
  • 5
  • 12
  • Hi please tag only relevant technologies, `react-native` tag appears to be irrelevant here. – Suraj Malviya Nov 27 '18 at 09:49
  • You are calling `handleSubmit` whereas the only method you declared was `handleUpload` – Damilola Nov 27 '18 at 09:51
  • @damilola can you please remove extra code from my code which is un-necessory – Brad Nov 27 '18 at 10:08
  • Try [axios](https://github.com/axios/axios) instead of whatever you are doing with reqwst and fetch. – c-chavez Nov 27 '18 at 10:15
  • @Brad Okay.. let's get things clear. What is the handleUpload function in the component doing – Damilola Nov 27 '18 at 10:23
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Nov 27 '18 at 19:04

0 Answers0