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

How to use
File
function
in
File

Best JavaScript code snippets using parse.File.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

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('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

function createProduct() {
 const file = new Parse.File(
  'name',
  {
   base64: new Buffer('download_file', 'utf-8').toString('base64'),
  },
  'text'
 );
 return file.save().then(function() {
  const product = new Parse.Object('_Product');
  product.set({
   download: file,
   icon: file,
   title: 'a product',
   subtitle: 'a product',
   order: 1,
   productIdentifier: 'a-product',
  });
  return product.save();
 });
}
origin: parse-community/parse-server

it('log in with provider with files', done => {
  const provider = getMockFacebookProvider();
  Parse.User._registerAuthenticationProvider(provider);
  const file = new Parse.File('yolo.txt', [1, 2, 3], 'text/plain');
  file
   .save()
   .then(file => {
    const user = new Parse.User();
    user.set('file', file);
    return user._linkWith('facebook', {});
   })
   .then(user => {
    expect(user._isLinked('facebook')).toBeTruthy();
    return Parse.User._logInWith('facebook', {});
   })
   .then(user => {
    const fileAgain = user.get('file');
    expect(fileAgain.name()).toMatch(/yolo.txt$/);
    expect(fileAgain.url()).toMatch(/yolo.txt$/);
   })
   .then(() => {
    done();
   })
   .catch(done.fail);
 });
origin: parse-community/parse-server

it('should create a server log on failure', done => {
  const logController = new LoggerController(new WinstonLoggerAdapter());

  reconfigureServer({ filesAdapter: mockAdapter })
   .then(() => new Parse.File('yolo.txt', [1, 2, 3], 'text/plain').save())
   .then(
    () => done.fail('should not succeed'),
    () => setImmediate(() => Promise.resolve('done'))
   )
   .then(() => new Promise(resolve => setTimeout(resolve, 200)))
   .then(() =>
    logController.getLogs({ from: Date.now() - 1000, size: 1000 })
   )
   .then(logs => {
    // we get two logs here: 1. the source of the failure to save the file
    // and 2 the message that will be sent back to the client.

    const log1 = logs.find(
     x => x.message === 'Error creating a file:  it failed with xyz'
    );
    expect(log1.level).toBe('error');

    const log2 = logs.find(x => x.message === 'it failed with xyz');
    expect(log2.level).toBe('error');
    expect(log2.code).toBe(130);

    done();
   });
 });
origin: parse-community/parse-server

it('autosave file in object in object', async done => {
  let file = new Parse.File('hello.txt', data, 'text/plain');
  ok(!file.url());

  const child = new Parse.Object('Child');
  child.set('file', file);

  const parent = new Parse.Object('Parent');
  parent.set('child', child);

  await parent.save();
  const query = new Parse.Query('Parent');
  query.include('child');
  const parentAgain = await query.get(parent.id);
  const childAgain = parentAgain.get('child');
  file = childAgain.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('login with provider should be blockable by beforeLogin even when the user has a attached file', async done => {
  const provider = getMockFacebookProvider();
  Parse.User._registerAuthenticationProvider(provider);

  let hit = 0;
  Parse.Cloud.beforeLogin(req => {
   hit++;
   if (req.object.get('isBanned')) {
    throw new Error('banned account');
   }
  });

  const user = await Parse.User._logInWith('facebook');
  const base64 = 'aHR0cHM6Ly9naXRodWIuY29tL2t2bmt1YW5n';
  const file = new Parse.File('myfile.txt', { base64 });
  await file.save();
  await user.save({ isBanned: true, file });
  await Parse.User.logOut();

  try {
   await Parse.User._logInWith('facebook');
   throw new Error('should not have continued login.');
  } catch (e) {
   expect(e.message).toBe('banned account');
  }

  expect(hit).toBe(1);
  done();
 });
origin: parse-community/parse-server

const file = new Parse.File('hello.txt', data, 'text/plain');
file.addMetadata('foo', 'bar');
await file.save();
origin: parse-community/parse-server

it('two saves at the same time', done => {
  const file = new Parse.File('hello.txt', data, 'text/plain');

  let firstName;
  let secondName;

  const firstSave = file.save().then(function() {
   firstName = file.name();
  });
  const secondSave = file.save().then(function() {
   secondName = file.name();
  });

  Promise.all([firstSave, secondSave]).then(
   function() {
    equal(firstName, secondName);
    done();
   },
   function(error) {
    ok(false, error);
    done();
   }
  );
 });
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('user login with files', done => {
  const file = new Parse.File('yolo.txt', [1, 2, 3], 'text/plain');
  file
   .save()
   .then(file => {
    return Parse.User.signUp('asdf', 'zxcv', { file: file });
   })
   .then(() => {
    return Parse.User.logIn('asdf', 'zxcv');
   })
   .then(user => {
    const fileAgain = user.get('file');
    ok(fileAgain.name());
    ok(fileAgain.url());
    done();
   })
   .catch(err => {
    jfail(err);
    done();
   });
 });
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('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('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)FileFile

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._name,
  • File._url,
  • File.addMetadata

Popular in JavaScript

  • path
  • winston
    A logger for just about everything.
  • q
    A library for promises (CommonJS/Promises/A,B,D)
  • mongodb
    The official MongoDB driver for Node.js
  • http
  • readable-stream
    Streams3, a user-land copy of the stream library from Node.js
  • minimatch
    a glob matcher in javascript
  • through2
    A tiny wrapper around Node.js streams.Transform (Streams2/3) to avoid explicit subclassing noise
  • commander
    the complete solution for node.js command-line programs
  • Top PhpStorm plugins
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