HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptMinor

Transferring file from Google to Parse.com

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
filegoogletransferringparsecomfrom

Problem

I have created a system where user selects files from their Google Drive to be uploaded into Parse.

I have done so separately though, where I have one code that allows user to select an item from Google Drive, and one that allows user to upload a file from their computer into parse.

Google Drive (Using Google drive picker):

`



eSnail Scan Upload Part 2



// The Browser API key obtained from the Google Developers Console.
var developerKey = 'KEY';

// The Client ID obtained from the Google Developers Console.
var clientId = 'ID';

// Scope to use to access user's photos.
var scope = ['https://www.googleapis.com/auth/photos'];

var pickerApiLoaded = false;
var oauthToken;

// Use the API Loader script to load google.picker and gapi.auth.
function onApiLoad() {
gapi.load('auth', {'callback': onAuthApiLoad});
gapi.load('picker', {'callback': onPickerApiLoad});
}

function onAuthApiLoad() {
window.gapi.auth.authorize(
{
'client_id': clientId,
'scope': scope,
'immediate': false
},
handleAuthResult);
}

function onPickerApiLoad() {
pickerApiLoaded = true;
createPicker();
}

function handleAuthResult(authResult) {
if (authResult && !authResult.error) {
oauthToken = authResult.access_token;
createPicker();
}
}

// Create and render a Picker object for picking user Photos.
function createPicker() {
if (pickerApiLoaded && oauthToken) {
var picker = new google.picker.PickerBuilder().
enableFeature(google.picker.Feature.MULTISELECT_ENABLED).
addView(google.picker.ViewId.PDFS).
setOAuthToken(oauthToken).
setDeveloperKey(developerKey).
setCallback(pickerCallback).
build();
picker.setVisib

Solution

You seem to separately download your file from Google, and then upload to Parse. So the "transfering" in the title is misleading.

Having said that, the code is well-structured but the naming is bad.

I find it semantically confusing to call your functions like onAuthApiLoad. This tells me nothing about what the function does.
Now, when I'm reading the line calling this functions, I have no clue what it does. On the other hand, I already see where it is called, so this name is more redundant than helpful:

onload=onApiLoad


is what I am talking about. The same for:

setCallback(pickerCallback)


If instead function's name tell me what it does, I can understand the line without even checking the function's definition!

I suspect saveJobApp is not specific to Job Applications, so a more generic name could be more helpful.

Why gameScore???

fileUploadControl is prob better to name fileUploadElement

Parse.initialize("ID", "ID");


will look better as

Parse.initialize("ParseID", "ParseJsKey");

Code Snippets

onload=onApiLoad
setCallback(pickerCallback)
Parse.initialize("ID", "ID");
Parse.initialize("ParseID", "ParseJsKey");

Context

StackExchange Code Review Q#75132, answer score: 4

Revisions (0)

No revisions yet.