Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Not Found when browsing to file url #8

Open
thewizster opened this issue May 26, 2016 · 12 comments
Open

File Not Found when browsing to file url #8

thewizster opened this issue May 26, 2016 · 12 comments

Comments

@thewizster
Copy link

I have configured azure storage on my local dev parse-server. I have success when saving/uploading files via the parse-dashboard.

But, while I have directAccess: false I get a response File not found from my parse-server.
The file url from the parse-dashboard is:
http://localhost:1337/parse/files/myAppId/welcome.jpg

When I set directAccess: true my file is downloaded successfully direct from azure storage.
The file url from the parse-dashboard is (account and container names changed):
https://storageaccount.blob.core.windows.net/container/welcome.jpg

parse-server: 2.2.10
parse-server-azure-storage: 1.0.4
parse-dashboard: 1.0.12

Thanks in advance for your assistance.

@felixrieseberg
Copy link
Owner

Hey, do you have some sample code? I just tried the whole flow again (just to be sure) and the following works just fine for me.

const Parse = require('parse/node');
const fs = require('fs');
const path = require('path');

Parse.initialize('myAppId');
Parse.serverURL = 'http://localhost:1337/parse'

// Test object
// const TestObject = Parse.Object.extend('TestObject');
// const testObject = new TestObject();

// testObject.save({foo: "bar"}).then((object) => {
//     console.log("yay! it worked");
// });

// Test file
fs.readFile(path.join(__dirname, 'image.jpg'), (err, data) => {
    const base64data = { base64: 'R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==' };
    const parseFile = new Parse.File('image.jpg', base64data);

    parseFile.save().then(() => console.log(parseFile.url()), (err) => console.log(err));
});

Would be helpful if you had an error - it's most likely to show up in parse-server.

@thewizster
Copy link
Author

Thanks for the followup @felixrieseberg, I appreciate you taking the time to respond with some sample code. I will setup a test project on my end and run through your code as well.

I'm not getting any error in parse-server with my setup.

In my scenario I am running on localhost while using the parse-dashboard to upload files and attempting to access files via the file url. I only get 'File not found' response when I try to browse to the file url with directAccess: false.

image

When I change to directAccess: true the parse-dashboard renders the direct Azure storage url and the file downloads from Azure when I browse it.

Here is how I have the server configured in code. I have environment variables set in my dev machine for my Azure storage account.

var ParseServer = require('parse-server').ParseServer;
var AzureStorageAdapter = require('parse-server-azure-storage').AzureStorageAdapter;

var azureStorageAccountName = process.env.AZURE_STORAGE_ACCOUNT_NAME || 'MyAccountName';
var azureStorageContainerName = process.env.AZURE_STORAGE_CONTAINER_NAME || 'parse';
var azureStorageOptions = {
  accessKey: process.env.AZURE_STORAGE_ACCESS_KEY || 'myAccessKey',
  directAccess: false // If set to true, files will be served by Azure Blob Storage directly
};

var api = new ParseServer({
  databaseURI: process.env.DATABASE_URI || 'mongodb://localhost:27017/parse',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.PARSE_APP_ID || 'myAppId',
  masterKey: process.env.PARSE_MASTER_KEY || 'myMasterKey',
  serverURL: process.env.PARSE_SERVER_URL || 'http://localhost:1337/parse',
  filesAdapter: new AzureStorageAdapter(azureStorageAccountName, azureStorageContainerName, azureStorageOptions)
});

@felixrieseberg
Copy link
Owner

Hm, I'm not sure about this one. Does it work fine with other file providers? I'm wondering what exactly might be happening here, since I'm not sure myself.

@thewizster
Copy link
Author

I have done some more testing using the example code you provided in your first response and here is what I have found.

  1. I ran the example code against my local parse-server with directAccess: false. File was saved successfully and URL still shows file not found.

  2. I set directAccess:true and re-ran the example code. File was saved and file was available via direct azure storage URL.

  3. I removed AzureStorageAdapter from the local parse-server config (This put parse-server back in default GridStoreAdapter mode). I re-ran the example code. File was saved and was available via local URL.

image

Then I created a new parse-server project from the parse example. I re-ran your example code against this new parse-server. I got the same results. Here is the full code of my new parse-server.

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var AzureStorageAdapter = require('parse-server-azure-storage').AzureStorageAdapter;
var app = express();

var azureStorageAccountName = process.env.AZURE_STORAGE_ACCOUNT_NAME || 'MyAccountName';
var azureStorageContainerName = process.env.AZURE_STORAGE_CONTAINER_NAME || 'parse';
var azureStorageOptions = {
  accessKey: process.env.AZURE_STORAGE_ACCESS_KEY || 'myAccessKey',
  directAccess: false // If set to true, files will be served by Azure Blob Storage directly
};

var api = new ParseServer({
  databaseURI: process.env.DATABASE_URI || 'mongodb://localhost:27017/dev', // Connection string for your MongoDB database
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', // Absolute path to your Cloud Code
  appId: 'myAppId',
  masterKey: 'myMasterKey', // Keep this key secret!
  serverURL: 'http://localhost:1337/parse', // Don't forget to change to https if needed
  filesAdapter: new AzureStorageAdapter(azureStorageAccountName, azureStorageContainerName, azureStorageOptions)
});

// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);

app.listen(1337, function() {
  console.log('parse-server-example running on port 1337.');
});

Is there anything else you could suggest to try? Thanks!

@pochadri
Copy link

pochadri commented Jun 9, 2016

+1

@majidhassan
Copy link

You need to set your publicServerUrl in index.js.

var server = ParseServer({..., publicServerURL: "https://example.com/parse", appName: "Parse App", ... });

If this doesn't fix it it might be an Azure related issue.

@thewizster
Copy link
Author

@majidhassan I tested this in my scenario but it did not solve the problem.

publicServerURL appears to be used for the email adapter. I found this in the README.md regarding publicServerURL.

  // The public URL of your app.
  // This will appear in the link that is used to verify email addresses and reset passwords.
  // Set the mount path as it is in serverURL
  publicServerURL: 'https://example.com/parse',

@majidhassan
Copy link

@thewizster it is only mentioned under the email adapter indeed, but is actually also used for the files url. But if you already tried that, then it might be an Azure issue.

@thewizster
Copy link
Author

@majidhassan Thanks for the clarification. I am going to leave publicServerURL in my config.

@GuichiZhao
Copy link

exactly the same issue

@GuichiZhao
Copy link

Here is hint for the bug :
The promise in getFileData promise is always rejected ,the error is { StorageError: The specified blob does not exist} .I suppose the file name do not match ,some kind of prefix is added somehow and @felixrieseberg may ignore it

@mnearents
Copy link

mnearents commented Jan 6, 2017

I'm having the same issue, is there a solution? One thing I've noticed, which may have nothing to do with the issue, is in the server configuration output, the storage name is always undefined:

storage: { name: undefined, container: 'parse', accessKey: 'ACCESSKEY', directAccess: true } }

Even though I have the following in my configuration setup:

var azureStorageAccountName = process.env.AZURE_STORAGE_NAME;
var azureStorageContainerName = process.env.AZURE_STORAGE_CONTAINER_NAME;
var azureStorageOptions = {
    accessKey: process.env.STORAGE_KEY,
    directAccess: false // If set to true, files will be served by Azure Blob Storage directly
};

config.server.filesAdapter = new AzureStorageAdapter(azureStorageAccountName, azureStorageContainerName, azureStorageOptions);

app.use('/parse', new ParseServer(config.server));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants