Upload files with help of api

Handle problems or report system bug
Post Reply
shrmaprem0202
Posts: 38
Joined: Tue Mar 07, 2023 7:13 pm
Contact:

Upload files with help of api

Post 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>
vikkas
Posts: 84
Joined: Sun May 07, 2023 9:28 am

Re: Upload files with help of api

Post 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
shrmaprem0202
Posts: 38
Joined: Tue Mar 07, 2023 7:13 pm
Contact:

Re: Upload files with help of api

Post 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
User avatar
FranciscoDC_
Posts: 7
Joined: Tue Jan 09, 2024 2:04 am

Re: Upload files with help of api

Post 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>
Web and Wapka Developer
https://wk.franciscodaschagas.dev
shrmaprem0202
Posts: 38
Joined: Tue Mar 07, 2023 7:13 pm
Contact:

Re: Upload files with help of api

Post 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
User avatar
FranciscoDC_
Posts: 7
Joined: Tue Jan 09, 2024 2:04 am

Re: Upload files with help of api

Post 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?
Web and Wapka Developer
https://wk.franciscodaschagas.dev
shrmaprem0202
Posts: 38
Joined: Tue Mar 07, 2023 7:13 pm
Contact:

Re: Upload files with help of api

Post 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
User avatar
FranciscoDC_
Posts: 7
Joined: Tue Jan 09, 2024 2:04 am

Re: Upload files with help of api

Post 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 = '/';
        }
Web and Wapka Developer
https://wk.franciscodaschagas.dev
shrmaprem0202
Posts: 38
Joined: Tue Mar 07, 2023 7:13 pm
Contact:

Re: Upload files with help of api

Post by shrmaprem0202 »

Thankyou so much for your help and support 🙏
Darshan
Posts: 1
Joined: Fri Nov 22, 2024 4:37 am

Re: Upload files with help of api

Post by Darshan »

User upload file HTML code chahie
Post Reply