Page 1 of 1

Upload files with help of api

Posted: Tue Jan 02, 2024 8:10 pm
by shrmaprem0202
Please help me in uploading file with api like

Code: Select all

https://api.wapka.org/FileCreator?apikey=<apikey>

Code: Select all

<form action="https://api.wapka.org/FileCreator" method="post">
  <input type="hidden" name="apikey" value="{{VAR(APIKEY)}}">
  <input name="dir" type="text" value=""><br>
  <input name="upload" type="file"><br>
  <input type="submit" value="Upload">
</form>

Re: Upload files with help of api

Posted: Wed Jan 03, 2024 2:37 am
by vikkas

Code: Select all

<form action="https://api.wapka.org/FileCreator" method="post" enctype="multipart/form-data">
  <input type="hidden" name="apikey" value="{{VAR(APIKEY)}}">
  <input name="dir" type="text" value="69529"><br>
  <input name="upload" type="file"><br>
  <input type="submit" value="Upload">
</form>
folder not found

Re: Upload files with help of api

Posted: Wed Jan 03, 2024 6:33 am
by shrmaprem0202
vikkas wrote: Wed Jan 03, 2024 2:37 am

Code: Select all

<form action="https://api.wapka.org/FileCreator" method="post" enctype="multipart/form-data">
  <input type="hidden" name="apikey" value="{{VAR(APIKEY)}}">
  <input name="dir" type="text" value="69529"><br>
  <input name="upload" type="file"><br>
  <input type="submit" value="Upload">
</form>
folder not found


I think something another variable for dir

Re: Upload files with help of api

Posted: Tue Jan 09, 2024 2:23 am
by FranciscoDC_
Quoting Administrator:
<dir> become <folderid>

Code: Select all

<form action="https://api.wapka.org/FileCreator" method="post" enctype="multipart/form-data">
  <input type="hidden" name="apikey" value="{{VAR(APIKEY)}}">
  <input name="folderid" type="text" value="69529"><br>
  <input name="upload" type="file"><br>
  <input type="submit" value="Upload">
</form>

Re: Upload files with help of api

Posted: Tue Jan 09, 2024 5:23 am
by shrmaprem0202
FranciscoDC_ wrote: Tue Jan 09, 2024 2:23 am Quoting Administrator:
<dir> become <folderid>

Code: Select all

<form action="https://api.wapka.org/FileCreator" method="post" enctype="multipart/form-data">
  <input type="hidden" name="apikey" value="{{VAR(APIKEY)}}">
  <input name="folderid" type="text" value="69529"><br>
  <input name="upload" type="file"><br>
  <input type="submit" value="Upload">
</form>

Wow thanks it's awesome i need one more help can i redirect to another page to api url

Re: Upload files with help of api

Posted: Tue Jan 09, 2024 2:23 pm
by FranciscoDC_
shrmaprem0202 wrote: Tue Jan 09, 2024 5:23 am Wow thanks it's awesome i need one more help can i redirect to another page to api url
For sure! You can do this in JavaScript using the JS Wrapper library for wapka API, but which URL would you like to redirect to?

Re: Upload files with help of api

Posted: Thu Jan 11, 2024 8:01 am
by shrmaprem0202
FranciscoDC_ wrote: Tue Jan 09, 2024 2:23 pm
shrmaprem0202 wrote: Tue Jan 09, 2024 5:23 am Wow thanks it's awesome i need one more help can i redirect to another page to api url
For sure! You can do this in JavaScript using the JS Wrapper library for wapka API, but which URL would you like to redirect to?
I want to redirect user to index page after upload a file how can can you give me a source code of that

Re: Upload files with help of api

Posted: Thu Jan 11, 2024 11:01 pm
by FranciscoDC_
shrmaprem0202 wrote: Thu Jan 11, 2024 8:01 am I want to redirect user to index page after upload a file how can can you give me a source code of that
Hello! I wasn't able to get the JS Wrapper library for the Wapka API to work, but anyway, here's a javascript code to allow you to upload the file and, if successful, redirect to the home page.

Code: Select all

<form action="https://api.wapka.org/FileCreator" method="post" enctype="multipart/form-data" onsubmit="return uploadFile()">
  <input type="hidden" name="folderid" id="folderInput" value="69529">
  <input type="hidden" name="apikey" id="apiKey" value="{{VAR(APIKEY)}}">
  <input name="upload" type="file" id="fileInput">
  <input type="submit" value="Upload">
</form>

<script type="text/javascript">
  function uploadFile() {
    let folderId = document.getElementById('folderInput').value;
    let apiKey = document.getElementById('apiKey').value;

    let formData = new FormData();
    formData.append('folderid', folderId);
    formData.append('apikey', apiKey);
    formData.append('upload', document.getElementById('fileInput').files[0]);

    let xhr = new XMLHttpRequest();
    xhr.open('POST', 'https://api.wapka.org/FileCreator', true);
    xhr.setRequestHeader('Accept', 'application/json');

    xhr.onload = function () {
      if (xhr.status >= 200 && xhr.status < 300) {
        let responseData = JSON.parse(xhr.responseText);
        console.log(responseData);

        if (responseData.ok) {
          window.location.href = '/';
        } else {
          console.error('Upload error:', responseData.error_type, responseData.description);
          alert('Error uploading file. Please try again. Details: ' + responseData.description);
        }
      } else {
        console.error('Request failed with status:', xhr.status);
        alert('Error during file upload. Please try again.');
      }
    };

    xhr.onerror = function () {
      console.error('Network error during the request.');
      alert('Error during file upload. Please try again.');
    };

    xhr.send(formData);

    return false;
  }
</script>
The relevant part is this, you can change '/' to any page you want to redirect, for example '/somepage', or even redirect to another website, for example 'https://google.com'.

Code: Select all

if (responseData.ok) {
          window.location.href = '/';
        }

Re: Upload files with help of api

Posted: Fri Jan 12, 2024 2:43 pm
by shrmaprem0202
Thankyou so much for your help and support 🙏