Tabnine Logo For Javascript
File
Code IndexAdd Tabnine to your IDE (free)

How to use
File
in
parse

Best JavaScript code snippets using parse.File(Showing top 15 results out of 315)

origin: parse-community/parse-server

it('saving an already saved file', async () => {
  const file = new Parse.File('hello.txt', data, 'text/plain');
  ok(!file.url());
  const result = await file.save();
  strictEqual(result, file);
  ok(file.name());
  ok(file.url());
  notEqual(file.name(), 'hello.txt');
  const previousName = file.name();

  await file.save();
  equal(file.name(), previousName);
 });
origin: parse-community/parse-server

it('beforeDeleteFile should call with fileObject', async () => {
  await reconfigureServer({ filesAdapter: mockAdapter });
  Parse.Cloud.beforeDeleteFile((req) => {
   expect(req.file).toBeInstanceOf(Parse.File);
   expect(req.file._name).toEqual('popeye.txt');
   expect(req.file._url).toEqual('http://www.somewhere.com/popeye.txt');
   expect(req.fileSize).toBe(null);
  });
  const file = new Parse.File('popeye.txt');
  await file.destroy({ useMasterKey: true });
 });
origin: parse-community/parse-server

const hasAllPODobject = () => {
 const obj = new Parse.Object('HasAllPOD');
 obj.set('aNumber', 5);
 obj.set('aString', 'string');
 obj.set('aBool', true);
 obj.set('aDate', new Date());
 obj.set('aObject', { k1: 'value', k2: true, k3: 5 });
 obj.set('aArray', ['contents', true, 5]);
 obj.set('aGeoPoint', new Parse.GeoPoint({ latitude: 0, longitude: 0 }));
 obj.set(
  'aFile',
  new Parse.File('f.txt', { base64: 'V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=' })
 );
 return obj;
}
origin: parse-community/parse-server

it('beforeSaveFile should throw error', async () => {
  await reconfigureServer({ filesAdapter: mockAdapter });
  Parse.Cloud.beforeSaveFile(() => {
   throw new Parse.Error(400, 'some-error-message');
  });
  const file = new Parse.File('popeye.txt', [1, 2, 3], 'text/plain');
  try {
   await file.save({ useMasterKey: true });
  } catch (error) {
   expect(error.message).toBe('some-error-message');
  }
 });
origin: parse-community/parse-server

it('beforeSaveFile should return file that is already saved and not save anything to files adapter', async () => {
  await reconfigureServer({ filesAdapter: mockAdapter });
  const createFileSpy = spyOn(mockAdapter, 'createFile').and.callThrough();
  Parse.Cloud.beforeSaveFile(() => {
   const newFile = new Parse.File('some-file.txt');
   newFile._url = 'http://www.somewhere.com/parse/files/some-app-id/some-file.txt';
   return newFile;
  });
  const file = new Parse.File('popeye.txt', [1, 2, 3], 'text/plain');
  const result = await file.save({ useMasterKey: true });
  expect(result).toBe(file);
  expect(result._name).toBe('some-file.txt');
  expect(result._url).toBe('http://www.somewhere.com/parse/files/some-app-id/some-file.txt');
  expect(createFileSpy).not.toHaveBeenCalled();
 });
origin: parse-community/parse-server

it('autosave file in object', async done => {
  let file = new Parse.File('hello.txt', data, 'text/plain');
  ok(!file.url());
  const object = new Parse.Object('TestObject');
  await object.save({ file });
  const objectAgain = await new Parse.Query('TestObject').get(object.id);
  file = objectAgain.get('file');
  ok(file instanceof Parse.File);
  ok(file.name());
  ok(file.url());
  notEqual(file.name(), 'hello.txt');
  done();
 });
origin: parse-community/parse-server

it('beforeSaveFile should return same file data with new file name', async () => {
  await reconfigureServer({ filesAdapter: mockAdapter });
  const config = Config.get('test');
  config.filesController.options.preserveFileName = true;
  Parse.Cloud.beforeSaveFile(async ({ file }) => {
   expect(file.name()).toBe('popeye.txt');
   const fileData = await file.getData();
   const newFile = new Parse.File('2020-04-01.txt', { base64: fileData });
   return newFile;
  });
  const file = new Parse.File('popeye.txt', [1, 2, 3], 'text/plain');
  const result = await file.save({ useMasterKey: true });
  expect(result.name()).toBe('2020-04-01.txt');
 });
origin: parse-community/parse-server

it('beforeSaveFile should not change file if nothing is returned', async () => {
  await reconfigureServer({ filesAdapter: mockAdapter });
  Parse.Cloud.beforeSaveFile(() => {
   return;
  });
  const file = new Parse.File('popeye.txt', [1, 2, 3], 'text/plain');
  const result = await file.save({ useMasterKey: true });
  expect(result).toBe(file);
 });
origin: parse-community/parse-server

it('file toJSON testing', async () => {
  const file = new Parse.File('hello.txt', data, 'text/plain');
  ok(!file.url());
  const object = new Parse.Object('TestObject');
  await object.save({
   file: file,
  });
  ok(object.toJSON().file.url);
 });
origin: parse-community/parse-server

it('afterSaveFile should change fileSize when file data changes', async (done) => {
  await reconfigureServer({ filesAdapter: mockAdapter });
  Parse.Cloud.beforeSaveFile(async (req) => {
   expect(req.fileSize).toBe(3);
   expect(req.master).toBe(true);
   const newFile = new Parse.File('donald_duck.pdf', [4, 5, 6, 7, 8, 9], 'application/pdf');
   return newFile;
  });
  Parse.Cloud.afterSaveFile(async (req) => {
   expect(req.fileSize).toBe(6);
   expect(req.master).toBe(true);
   done();
  });
  const file = new Parse.File('popeye.txt', [1, 2, 3], 'text/plain');
  await file.save({ useMasterKey: true });
 });
origin: parse-community/parse-server

it('save file in object with escaped characters in filename', async () => {
  const file = new Parse.File('hello . txt', data, 'text/plain');
  ok(!file.url());
  const result = await file.save();
  strictEqual(result, file);
  ok(file.name());
  ok(file.url());
  notEqual(file.name(), 'hello . txt');

  const object = new Parse.Object('TestObject');
  await object.save({ file });
  const objectAgain = await new Parse.Query('TestObject').get(object.id);
  ok(objectAgain.get('file') instanceof Parse.File);
 });
origin: parse-community/parse-server

it('beforeDeleteFile should throw error', async (done) => {
  await reconfigureServer({ filesAdapter: mockAdapter });
  Parse.Cloud.beforeDeleteFile(() => {
   throw new Error('some error message');
  });
  const file = new Parse.File('popeye.txt');
  try {
   await file.destroy({ useMasterKey: true });
  } catch (error) {
   expect(error.message).toBe('some error message');
   done();
  }
 })
origin: parse-community/parse-server

it('save file', async () => {
  const file = new Parse.File('hello.txt', data, 'text/plain');
  ok(!file.url());
  const result = await file.save();
  strictEqual(result, file);
  ok(file.name());
  ok(file.url());
  notEqual(file.name(), 'hello.txt');
 });
origin: parse-community/parse-server

it('afterSaveFile should throw error', async () => {
  await reconfigureServer({ filesAdapter: mockAdapter });
  Parse.Cloud.afterSaveFile(async () => {
   throw new Parse.Error(400, 'some-error-message');
  });
  const filename = 'donald_duck.pdf';
  const file = new Parse.File(filename, [1, 2, 3], 'text/plain');
  try {
   await file.save({ useMasterKey: true });
  } catch (error) {
   expect(error.message).toBe('some-error-message');
  }
 });
origin: parse-community/parse-server

it('save file in object', async done => {
  const file = new Parse.File('hello.txt', data, 'text/plain');
  ok(!file.url());
  const result = await file.save();
  strictEqual(result, file);
  ok(file.name());
  ok(file.url());
  notEqual(file.name(), 'hello.txt');

  const object = new Parse.Object('TestObject');
  await object.save({ file: file });
  const objectAgain = await new Parse.Query('TestObject').get(object.id);
  ok(objectAgain.get('file') instanceof Parse.File);
  done();
 });
parse(npm)File

Most used parse functions

  • Cloud
  • Config
  • User
  • ACL
  • ACL.ACL
  • ACL.setPublicReadAccess,
  • ACL.setPublicWriteAccess,
  • ACL.setReadAccess,
  • ACL.setRoleReadAccess,
  • ACL.setRoleWriteAccess,
  • ACL.setWriteAccess,
  • Analytics,
  • Error,
  • FacebookUtils,
  • File,
  • File.File,
  • File._name,
  • File._url,
  • File.addMetadata

Popular in JavaScript

  • q
    A library for promises (CommonJS/Promises/A,B,D)
  • mocha
    simple, flexible, fun test framework
  • cheerio
    Tiny, fast, and elegant implementation of core jQuery designed specifically for the server
  • chalk
    Terminal string styling done right
  • moment
    Parse, validate, manipulate, and display dates
  • body-parser
    Node.js body parsing middleware
  • minimist
    parse argument options
  • postcss
  • glob
    a little globber
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJavascript Code Index
Get Tabnine for your IDE now