Skip to content

Instantly share code, notes, and snippets.

@classmember
Last active February 23, 2023 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save classmember/72ab335223722623af9ed5346e5ed6eb to your computer and use it in GitHub Desktop.
Save classmember/72ab335223722623af9ed5346e5ed6eb to your computer and use it in GitHub Desktop.
OpenAI_client.js
// Prompt:
// Write a frontend JavaScript function to upload a .zip file from a chrome extension in a browser to a node backend using express. The code must publish to a POST endpoint over HTTPS.
// Response:
// Note: This code assumes the use of jQuery for the AJAX request
function uploadZipFile(file) {
let formData = new FormData();
formData.append('file', file);
$.ajax({
type: 'POST',
url: 'https://mybackend.com/upload',
data: formData,
contentType: false,
processData: false,
success: (data) => {
console.log(`Upload successful!`);
},
error: (err) => {
console.log(`Upload failed: ${err}`);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment