Laravel uploaded image fires a 404 Not Found error - file-upload

I've written a Laravel 5.3 app that uploads an image and saves its details to the database. When I used it on localhost, everything worked fine. As soon as I uploaded it to Forge, all images uploaded via the app return a 404 code instead of displaying the image.
Some details:
The new files are uploaded correctly. I can access them via console and ls -l the files.
The new files have the same permissions and owner as the files I have uploaded via local and then pushed to the server. The old files (those pushed) are showing. The new files (those newly uploaded) are giving 404.
The new files and the old files have an identical URL structure. That is, they both go to /storage/uploads/file_name.jpg
The upload code:
if($image = $request->file('image')) {
$file_data = [];
$file_data['path'] = $image->store('uploads', 'public');
$file_details = pathinfo($file_data['path']);
$file_data['url'] = 'uploads/';
$file_data['filename'] = $file_details['filename'];
$file_data['extension'] = $file_details['extension'];
$file_data['is_image'] = 1;
$file = new File($file_data);
$file->save();
$data['image'] = $file->id;
}
Help, please!

Related

Is there a consistent way for a .net core webapp & console app to determine path to datafiles folder?

I have two apps that share a data files folder. One is an asp.net core web app. The other is a .net core console app. Folder structure is:
WebApp
WorkflowApp
Datafiles
If I use any of these in the console app:
string en = Environment.CurrentDirectory;
string dr = Directory.GetCurrentDirectory();
string ad = AppDomain.CurrentDomain.BaseDirectory;
string sa = System.AppContext.BaseDirectory;
they all point to: workflow\bin\Debug\netcoreapp2.0
If I use them in the webapp, then en & dr point to "webapp" and the others point to "webapp\bin\Debug\netcoreapp2.0
I'm using appsettings.json to set the path to Datafiles. This file is shared by WebApp and WorkflowApp. I was setting it to "../Datafiles" and then getting the full path using:
Path.Combine(Directory.GetCurrentDirectory(), datafiles);
But this only works in WebApp. I would like to find a common method that works for both. And I don't want to set an absolute path in appsettings.json.
I could use AppDomain.CurrentDomain.BaseDirectory and then use:
#"..\..\..\..\Datafiles"
to move back from a "bin\Debug\netcoreapp2.0" folder. But this seems a bit convoluted. Is there a better way?
EDIT: An answer to this question might solve my problem (at least when in development): How can I get the path to the project folder (where the .csproj file is located) from in the code?
Try this way.
var requiredPath = "";
var address = "DataFiles";
var rootDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
if (rootDir != null)
{
requiredPath = Path.Combine(rootDir, address);
}
I would not let the application figure out the directory / path of where the data files are but rather externalize the paths into a config such as in appSettings.json or something similar.
If you then want to take it a step further and have the apps share the same config you can use a cetnralized store such as Consul or Etcd
https://github.com/etcd-io/etcd
https://www.consul.io/api/kv.html

Wiki Parsoid error - cannot connect to Parsoid Server

I'm trying to set Parsoid extension and Visual Editor on my wiki page. It is NOT on my localhost. Those who will use the Visual Editor must log in, but the content of the wiki can be read without logging in.
The address is http://contractor.bg/wikimedia/index.php?title=Main_Page
I downloaded the Parsoid extension (in the extension files there is no settings.js file, so I created it according to an example).
My settings are:
in the LocalSettings.php file:
require_once "$IP/extensions/VisualEditor/VisualEditor.php";
$wgDefaultUserOptions['visualeditor-enable'] = 1;
$wgHiddenPrefs[] = 'visualeditor-enable';
wfLoadExtension( 'Parsoid' );
$wgVisualEditorParsoidURL = 'http://contractor.bg:2083';
$wgVisualEditorParsoidPrefix = 'wikimedia';
//$wgSessionsInObjectCache = true;
//$wgVisualEditorParsoidForwardCookies = true;
//$wgVisualEditorParsoidTimeout = 120;
I tried with to uncomment the last lines, but it still does not work.
In the settings.js file:
parsoidConfig.setMwApi( 'wikimedia', { uri: 'http://contractor.bg/wikimedia/api.php' } ); // I also tried setting an interwiki value, I am not quite sure what is the difference)
parsoidConfig.serverPort = 2083;
parsoidConfig.serverInterface = 'contractor.bg';
parsoidConfig.strictSSL = false;
parsoidConfig.allowCORS = 'contractor.bg/wikimedia'; // I also tried only contractor.bg)
At the moment when I try to Edit a page with the Visual Editor, I receive an error:
Error loading data from server: 401: parsoidserver-http: HTTP 401. Would you like to retry?
Parsoid is not a MediaWiki extension (well, there was an extension with this name as a support mechanism for the actual Parsoid, but it was never standalone and is no longer required). It is an external service.
You need to actually start the Parsoid service by running node bin/server.js from the Parsoid directory. Ensure it is actually running on the port you specify in the VisualEditor config (2083) - it looks like you have something else there.

Rotativa file not found on server only

I am using Rotativa ActionasPDF() to generate a pdf from a view in my MVC4 project. It works flawlessly on my local instance, but I just copied the entire solution to my server and it does not work. I get the error "The system cannot find the file specified", but I'm not sure what file it is talking about. I assume it is talking about the Rotativa dll, but I've got the generated Rotativa folder on my server as well. The solution is an exact duplicate as my local copy. My site is hosted on IIS 8, windows 2012 server. Research has told me I could have a permissions issue with some folder, but I'm not sure which ones they would be. I just set all my controller & views to 777 permissions for the time being. No luck. Any ideas to what I'm missing, or how I can make sure the dll is registered on my server?
Here is my controller action method:
public ActionResult DownloadFile(int id = 0)
{
var filename = string.Format("Invoice{0}.pdf", id);
return new ActionAsPdf("Invoice" + "/" + id, new { name = "Invoice" + id }) { FileName = filename, PageSize = Size.Letter, PageOrientation = Orientation.Portrait, PageMargins = new Margins(0, 0, 0, 0) };
}
Check if you add all files in rotativa directory on server-
libeay32.dll
wkhtmltopdf.exe
etc.
Old thread but I had the same issue so I wanted to share the solution for people searching in the future.
Ensure you have the correct VS Redistributable installed on the server, or files in the Rotativa folder.
Use the server IP address instead of the DNS name. I do not know why this works but will edit this if I figure it out.
You need to have Visual C++ Redistributable Packages on the server. You can download the packages from here: http://www.microsoft.com/en-gb/download/details.aspx?id=40784
You need update Rotativa, Rotativa.Core, Rotativa.MVC in Nuget

How to load local resources?

How can I access the resources (CSS, JS and images stored in the project folders) from Worklight?
For example is there an absolute path (a Worklight URL) that points to local internal Worklight resources? Or is maybe another way to load resources from filesystem?
(The reason I'm trying to load resources from local is to speed up the page loading)
Edit: from discussion in the comments it sounds like only looking at the filesystem in the rooted device should suffice.
Edit 2: If what you are looking for is the fastest option to load resources, you shouldn't load them remotely to begin with. Put the index.html in the device. You can't both use Portal to load content remotely, and expect fast loading time. By definition, by loading content remotely, you Will experience possible slowdowns.
Worklight does not supply this path.
Theoretically, you may be able to access the application's sandbox (and thus the web resources) by using the Cordova File API.
You can get a reference to the device's filesystem:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
From there you could access the application's sandbox and find the desired file(s). Since you are the one putting the resources in the app, you should know where you've placed it.
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
}
To experiment and find out the paths to the content, you can root your device and then via Eclipse you could traverse the file system. This way you should be able to find the path to the file you've placed.
The only way I managed to access local fiiles in Worklight running an Android environment is using a XMLHttpRequest:
//Works only on Android
function prendiCaricaRisorsaWorklight(percorsoPiuNomeFile) {
var xmlhttp = new XMLHttpRequest();
var risposta = "";
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4
&& (xmlhttp.status == 200 || xmlhttp.status == 0)) {
risposta = xmlhttp.responseText;
alert(risposta);
}
}
xmlhttp.open("GET", "file:///android_asset/www/default/"
+ percorsoPiuNomeFile, true);
xmlhttp.send(null);
}
Usage example:
prendiCaricaRisorsaWorklight("css/cssInterno.css");
prendiCaricaRisorsaWorklight("js/jsInterno.js");
This shows on Android an alert with the file content.

Unable to configure SabreDAV to test Webdav and CardDAV

Steps I followed:
Downloaded the Sabredav zip file - unzipped it.
Downloaded apache webserver 2.2 and PHP 5.3
Then followed the instructions mentioned in the 'get Started' section on Sabredav website.
Created 'data and public' fiels (located them in /sabredav/vendor/)
Created the server.php file (located it in /sabredav/vendor/)
Now tried to open the server.php file in browser -
Here it opens using the file protocol..
Fails to open in expected - 'http ://mydomain/sabredav/server.php
Can anybody please help me on this ?
Thanks
In server.php, use the browser plugin tu see files in Public folder.
Your server must be like this:
include 'SabreDAV/vendor/autoload.php';
use
Sabre\DAV;
$rootDirectory = new DAV\FS\Directory('public');
// The server object is responsible for making sense out of the WebDAV protocol
$server = new DAV\Server($rootDirectory);
// If your server is not on your webroot, make sure the following line has the correct information
$server->setBaseUri('/server.php'); // if its in some kind of home directory
// The lock manager is reponsible for making sure users don't overwrite each others changes. Change 'data' to a different
// directory, if you're storing your data somewhere else.
$lockBackend = new DAV\Locks\Backend\File('data/locks');
$lockPlugin = new DAV\Locks\Plugin($lockBackend);
$server->addPlugin($lockPlugin);
$server->addPlugin(new \Sabre\DAV\Browser\GuessContentType());
$plugin = new \Sabre\DAV\Browser\Plugin();
$server->addPlugin($plugin);
// All we need to do now, is to fire up the server
$server->exec();