Click here to Skip to main content
15,886,802 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionCan't match this string in typescript using if and else if Pin
jkirkerx18-Sep-18 13:04
professionaljkirkerx18-Sep-18 13:04 
QuestionHow to cancel a drag event Pin
jkirkerx18-Sep-18 9:25
professionaljkirkerx18-Sep-18 9:25 
AnswerRe: How to cancel a drag event Pin
Richard Deeming18-Sep-18 10:53
mveRichard Deeming18-Sep-18 10:53 
GeneralRe: How to cancel a drag event Pin
jkirkerx18-Sep-18 11:54
professionaljkirkerx18-Sep-18 11:54 
Questioncouldn't read from datalist Pin
thepast16-Sep-18 21:01
thepast16-Sep-18 21:01 
QuestionHow to pass JavaScript output to an HTML String Variable outside the <script>? Pin
Member 1348136115-Sep-18 15:45
Member 1348136115-Sep-18 15:45 
AnswerRe: How to pass JavaScript output to an HTML String Variable outside the <script>? Pin
Richard Deeming18-Sep-18 3:45
mveRichard Deeming18-Sep-18 3:45 
QuestionTrouble uploading files with aws s3 Pin
Member 1398382813-Sep-18 13:15
Member 1398382813-Sep-18 13:15 
1) What I'm trying to do: Uploading a file with aws s3 and then taking the filename and filetype and placing it at the end of the url to save it in sql so that every time the person logs in, it will pull the picture up by user image url

2) Problem: Not uploading and not recognizing file in filename or filetype. Coming up with undefined for filetype and filename in URL and signedURL

3) fileUploadService.js USED IN NODEJS (below)

Can anyone let me know what I'm doing wrong or anything missing?


const aws = require('aws-sdk');
aws.config.region = 'us-west-2';
aws.config.update({ accessKeyId: '', secretAccessKey: '' });
const PROFILE_S3_LINK = "https://sabio-training.s3.amazonaws.com/";
module.exports = {
  getUrl: getUrl
}
function getUrl(req, res) {
  const s3 = new aws.S3();
  const fileName = 'C56/'+"filename"+'/' ;    //hardcoded filename and filetype for it to work.
  const fileType = "filetype";              //How to take filename from uploaded file to insert into "fileName" along with the "filetype"?
  const s3Params = {                                        getSignedURL looks like this : https://sabio-training.s3.us-west-2.amazonaws.com/C56/filename/?AWSAccessKeyId=AKIAJF53EJKW7SJUV55Q&Content-Type=filetype&
    Bucket: 'sabio-training',                                                                       Expires=1536877443&Signature=WxSvLSzfyZKDRN9LawVOwj1ayVY%3D&x-amz-acl=public-read
    Key: fileName,                                            URL looks like this :                 https://sabio-training.s3.amazonaws.com/C56/filename/filetype
    Expires: 3000,
    ContentType: fileType,
    ACL: 'public-read'
  };
  s3.getSignedUrl('putObject', s3Params, (err, data) => {
    if (err) {
      console.log(err);
      return res.end();
    }
    const returnData = {
      signedRequest: data,
      url: `${PROFILE_S3_LINK}${fileName}${fileType}` //unsigned URL
    };
    res.write(JSON.stringify(returnData));
    res.end();
  });
}
=========================================================================
fileUploadRoute.js
const router = require("express").Router();
const fileUploadController = require("../controllers/fileUploadController")
router.put("/", fileUploadController.getUrl);
module.exports = router;
==========================================================================
fileUploadController.js
const fileUploadService = require('../services/fileUploadService')
const responses = require("../models/responses");
module.exports = {
    getUrl: getUrl
}
function getUrl(req, res) {
    fileUploadService.getUrl(req, res)
        .then(response => {
            res.send(response)
        })
        .catch(error => {
            res.send(error)
        })
}
===========================================================================
index.js in node portion
const router = require("express").Router();
const pogsRoutes = require("./pogs.routes");
const userFromJWT = require("../filters/jwt.user");
const validateUser = require("../filters/validate.user");
const testRoutes = require("./test.routes");
const profileRoute = require("../profile/profileRoute");
const fileUploadRoute = require("../fileUpload/fileUploadRoute")
module.exports = router;
// router.use("/api/profilePage", profileRoute)
router.use("/api/pogs", pogsRoutes);
router.use("/api/upload", fileUploadRoute)
router.use("/api/profilePage", profileRoute)
// -----------------------------------
// Authenticated routes go below this:
// -----------------------------------
router.use(userFromJWT);
router.use(validateUser);
router.use("/api/test", testRoutes); // TODO: remove this before delivery to the client
============================================================================
USED IN REACT
Axios pulled from profile page
handleClickUpload = evt => {
        evt.preventDefault()
        console.log("RESULT : ", this.state);
        // var file = evt.target.files[0]; <-- havent used this yet but I know its for upload
        axios.put(`${NODE_API_URL}/api/upload`, {
                // f:file
        })
        .then(response =>{
                console.log(
                response,"URL SIGNED REQUEST : ",response.data.signedRequest, " URL : ",response.data.url
                )
        })
        .catch(error => {
                console.log(error);
        })
}
Upload button and file upload portion inside profile page
               <div method="post" encType="multipart/form-data" action="/">
        <input type="file" name="fileName" className="btn" />
        <input type="submit" value="Upload" className="btn" onClick={this.handleClickUpload}/>

AnswerRe: Trouble uploading files with aws s3 Pin
jkirkerx1-Oct-18 8:04
professionaljkirkerx1-Oct-18 8:04 
Questiongetting error period.draggable is not a function Pin
Gopal Kan12-Sep-18 19:49
Gopal Kan12-Sep-18 19:49 
AnswerRe: getting error period.draggable is not a function Pin
Graham Breach12-Sep-18 21:08
Graham Breach12-Sep-18 21:08 
QuestionModal popup with datalist Pin
thepast12-Sep-18 8:18
thepast12-Sep-18 8:18 
QuestionJavascript and extensions Pin
Member 1398114211-Sep-18 15:10
Member 1398114211-Sep-18 15:10 
QuestionWhen pressing right and left keys object not moving in javascript game. Pin
Member 1396097131-Aug-18 11:10
Member 1396097131-Aug-18 11:10 
QuestionAngular 6, lazy loading, with routerLink="/reviews" it works, type the Url localhost:5000/reviews and page not found Pin
jkirkerx17-Aug-18 13:06
professionaljkirkerx17-Aug-18 13:06 
AnswerRe: Angular 6, lazy loading, with routerLink="/reviews" it works, type the Url localhost:5000/reviews and page not found Pin
jkirkerx18-Aug-18 13:31
professionaljkirkerx18-Aug-18 13:31 
General[Solved] Pin
jkirkerx20-Aug-18 9:25
professionaljkirkerx20-Aug-18 9:25 
QuestionCoding Newbie Pin
Rokas Steiblys17-Aug-18 10:21
Rokas Steiblys17-Aug-18 10:21 
AnswerRe: Coding Newbie Pin
Richard MacCutchan17-Aug-18 21:37
mveRichard MacCutchan17-Aug-18 21:37 
AnswerRe: Coding Newbie Pin
Nathan Minier20-Aug-18 1:34
professionalNathan Minier20-Aug-18 1:34 
SuggestionRe: Coding Newbie Pin
Member 1395671021-Aug-18 6:28
Member 1395671021-Aug-18 6:28 
QuestionExsplicit JavaScript regular exspression Pin
calmchess16-Aug-18 13:17
calmchess16-Aug-18 13:17 
AnswerRe: Explicit JavaScript regular expression Pin
Richard Deeming17-Aug-18 7:02
mveRichard Deeming17-Aug-18 7:02 
QuestionUsing data from odata in react-native Pin
Mike V Baker12-Aug-18 16:59
Mike V Baker12-Aug-18 16:59 
AnswerRe: Using data from odata in react-native Pin
Richard MacCutchan12-Aug-18 21:03
mveRichard MacCutchan12-Aug-18 21:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.