How to upload the file that has been detected as a new addition to an URL?How to detect if JavaScript is disabled?How do I detect a click outside an element?How can I upload files asynchronously?How do I modify the URL without reloading the page?How do I include a JavaScript file in another JavaScript file?jQuery Ajax File UploadOpen a URL in a new tab (and not a new window) using JavaScriptHow can I add new array elements at the beginning of an array in Javascript?Call to xmlhttprequest from page onload event is not working OK when Back from another pageFile upload to pre-signed url of S3 in React Native - Header is getting appended

Gold Battle KoTH

Can I shorten this filter, that finds disk sizes over 100G?

The grades of the students in a class

How to escape forward slashes?

Adding a (stair/baby) gate without facing walls

How to gracefully excuse yourself from a meeting due to emergencies such as a restroom break?

How to compare files with diffrent extensions and delete extra files?

Why did the United States not resort to nuclear weapons in Vietnam?

PI 4 screen rotation from the terminal

How do I safety check that there is no light in Darkroom / Darkbag?

Return last number in sub-sequences in a list of integers

When did J.K. Rowling decide to make Harry and Ginny a couple?

Is Norway in the Single Market?

How does one get a visa to go to Saudi Arabia?

Being told my "network" isn't PCI Complaint. I don't even have a server! Do I have to comply?

Is the EU really banning "toxic propellants" in 2020? How is that going to work?

UX writing: When to use "we"?

Adjective for when skills are not improving and I'm depressed about it

How can flights operated by the same company have such different prices when marketed by another?

Cross out words with TikZ: line opacity

How to trick a fairly simplistic kill-counter?

Can I say "Gesundheit" if someone is coughing?

A conjectural trigonometric identity

What is the most 'environmentally friendly' way to learn to fly?



How to upload the file that has been detected as a new addition to an URL?


How to detect if JavaScript is disabled?How do I detect a click outside an element?How can I upload files asynchronously?How do I modify the URL without reloading the page?How do I include a JavaScript file in another JavaScript file?jQuery Ajax File UploadOpen a URL in a new tab (and not a new window) using JavaScriptHow can I add new array elements at the beginning of an array in Javascript?Call to xmlhttprequest from page onload event is not working OK when Back from another pageFile upload to pre-signed url of S3 in React Native - Header is getting appended






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I need to upload to a URL a file notified as a new addition to the folder I am watching. How do I do this without forms?



I am writing a basic file synchroniser that uses an Electron desktop app as client, Python server and AWS endpoint. I am using presigned URL for upload/download requests and have chokidar to watch the folder set up for sync.



When I get notified of Add through Chokidar, I make a call to my Python server and get a presigned URL for upload. This part works fine.



Once I get the URL, I need to upload the file. I have no HTML component associated with this operation (and do not want to add) I read that I can upload file using AJAX with formdata but it requires "data" column. How do I fill this?



 watcher
.on('add', function(dir)
console.log('File', dir, 'has been added');
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
results.innerHTML = '';

data = JSON.stringify("operation": "uploadFile", "bucketName": "deadlinefighters", "fileDetails": "fileName": dir.replace(/^.*[\/]/, ''));

xhr.onreadystatechange = function ()
if (xhr.readyState === 4 && xhr.status === 200)
jsonResponse = JSON.parse(xhr.responseText);

var content;

fs.readFile(dir, function read(err, data)
if (err)
throw err;

content = data;
);

$.ajax(
url: jsonResponse["url"],
type: 'PUT',
data: content, //This is the part I do not know how to fill right
async: false,
success: function ()
results.innerHTML = "Uploaded!"

);
listObjectsinServer();

else if(xhr.status!=200)
results.innerHTML = 'ERROR!';

;
xhr.send(data);

)


I tried fs.readFile but it does not work either. Based on some SO answers, I put the AJAX call inside but even that did not work. I feel like I might be misunderstanding this field.










share|improve this question






























    0















    I need to upload to a URL a file notified as a new addition to the folder I am watching. How do I do this without forms?



    I am writing a basic file synchroniser that uses an Electron desktop app as client, Python server and AWS endpoint. I am using presigned URL for upload/download requests and have chokidar to watch the folder set up for sync.



    When I get notified of Add through Chokidar, I make a call to my Python server and get a presigned URL for upload. This part works fine.



    Once I get the URL, I need to upload the file. I have no HTML component associated with this operation (and do not want to add) I read that I can upload file using AJAX with formdata but it requires "data" column. How do I fill this?



     watcher
    .on('add', function(dir)
    console.log('File', dir, 'has been added');
    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/json");
    results.innerHTML = '';

    data = JSON.stringify("operation": "uploadFile", "bucketName": "deadlinefighters", "fileDetails": "fileName": dir.replace(/^.*[\/]/, ''));

    xhr.onreadystatechange = function ()
    if (xhr.readyState === 4 && xhr.status === 200)
    jsonResponse = JSON.parse(xhr.responseText);

    var content;

    fs.readFile(dir, function read(err, data)
    if (err)
    throw err;

    content = data;
    );

    $.ajax(
    url: jsonResponse["url"],
    type: 'PUT',
    data: content, //This is the part I do not know how to fill right
    async: false,
    success: function ()
    results.innerHTML = "Uploaded!"

    );
    listObjectsinServer();

    else if(xhr.status!=200)
    results.innerHTML = 'ERROR!';

    ;
    xhr.send(data);

    )


    I tried fs.readFile but it does not work either. Based on some SO answers, I put the AJAX call inside but even that did not work. I feel like I might be misunderstanding this field.










    share|improve this question


























      0












      0








      0








      I need to upload to a URL a file notified as a new addition to the folder I am watching. How do I do this without forms?



      I am writing a basic file synchroniser that uses an Electron desktop app as client, Python server and AWS endpoint. I am using presigned URL for upload/download requests and have chokidar to watch the folder set up for sync.



      When I get notified of Add through Chokidar, I make a call to my Python server and get a presigned URL for upload. This part works fine.



      Once I get the URL, I need to upload the file. I have no HTML component associated with this operation (and do not want to add) I read that I can upload file using AJAX with formdata but it requires "data" column. How do I fill this?



       watcher
      .on('add', function(dir)
      console.log('File', dir, 'has been added');
      xhr.open("POST", url, true);
      xhr.setRequestHeader("Content-Type", "application/json");
      results.innerHTML = '';

      data = JSON.stringify("operation": "uploadFile", "bucketName": "deadlinefighters", "fileDetails": "fileName": dir.replace(/^.*[\/]/, ''));

      xhr.onreadystatechange = function ()
      if (xhr.readyState === 4 && xhr.status === 200)
      jsonResponse = JSON.parse(xhr.responseText);

      var content;

      fs.readFile(dir, function read(err, data)
      if (err)
      throw err;

      content = data;
      );

      $.ajax(
      url: jsonResponse["url"],
      type: 'PUT',
      data: content, //This is the part I do not know how to fill right
      async: false,
      success: function ()
      results.innerHTML = "Uploaded!"

      );
      listObjectsinServer();

      else if(xhr.status!=200)
      results.innerHTML = 'ERROR!';

      ;
      xhr.send(data);

      )


      I tried fs.readFile but it does not work either. Based on some SO answers, I put the AJAX call inside but even that did not work. I feel like I might be misunderstanding this field.










      share|improve this question














      I need to upload to a URL a file notified as a new addition to the folder I am watching. How do I do this without forms?



      I am writing a basic file synchroniser that uses an Electron desktop app as client, Python server and AWS endpoint. I am using presigned URL for upload/download requests and have chokidar to watch the folder set up for sync.



      When I get notified of Add through Chokidar, I make a call to my Python server and get a presigned URL for upload. This part works fine.



      Once I get the URL, I need to upload the file. I have no HTML component associated with this operation (and do not want to add) I read that I can upload file using AJAX with formdata but it requires "data" column. How do I fill this?



       watcher
      .on('add', function(dir)
      console.log('File', dir, 'has been added');
      xhr.open("POST", url, true);
      xhr.setRequestHeader("Content-Type", "application/json");
      results.innerHTML = '';

      data = JSON.stringify("operation": "uploadFile", "bucketName": "deadlinefighters", "fileDetails": "fileName": dir.replace(/^.*[\/]/, ''));

      xhr.onreadystatechange = function ()
      if (xhr.readyState === 4 && xhr.status === 200)
      jsonResponse = JSON.parse(xhr.responseText);

      var content;

      fs.readFile(dir, function read(err, data)
      if (err)
      throw err;

      content = data;
      );

      $.ajax(
      url: jsonResponse["url"],
      type: 'PUT',
      data: content, //This is the part I do not know how to fill right
      async: false,
      success: function ()
      results.innerHTML = "Uploaded!"

      );
      listObjectsinServer();

      else if(xhr.status!=200)
      results.innerHTML = 'ERROR!';

      ;
      xhr.send(data);

      )


      I tried fs.readFile but it does not work either. Based on some SO answers, I put the AJAX call inside but even that did not work. I feel like I might be misunderstanding this field.







      javascript electron chokidar






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 26 at 23:40









      BhargBharg

      741 silver badge10 bronze badges




      741 silver badge10 bronze badges

























          0






          active

          oldest

          votes










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367720%2fhow-to-upload-the-file-that-has-been-detected-as-a-new-addition-to-an-url%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367720%2fhow-to-upload-the-file-that-has-been-detected-as-a-new-addition-to-an-url%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현