How to add image to hugo with local and remote - hugo

I want add an image to hugo's md file. And I want see it on local and website, and use a single directory to store it. So I try to put it on /content/posts/image/xxx.img and write md file with ![](/content/posts/images/2022-11-10-17-33-49.png) it's work in vscode but not in website. Is there way to get it?

Find it in hugo https://discourse.gohugo.io/t/how-to-add-image-to-hugo-with-local-and-remote/41391/8
The answer is change the conf file.
[[module.mounts]]
source = 'static'
target = 'static'
[[module.mounts]]
source = 'images'
target = 'static/images'

Related

Drupal upload then move doesn't update path or filename in file list

I have a custom form using a "managed_file" which uploads to temp folder. Programmatically, I then load that file and move it to its permanent storage (overwriting any existing file with the* name) e.g.
// Upload file
$upfile = $this->entityTypeManager->getStorage('file')->load($fid);
// Source and destination
$sourceUri = $this->fileSystem->realpath($upfile->getFileUri());
$destinationUri = $this->fileSystem->realpath(\Drupal::config('system.file')->get('default_scheme') . "://") . '/x/y/z/XYZ_NEW.pdf';
// Move and overwrite
$this->fileSystem->move($sourceUri, $destinationUri, FileSystemInterface::EXISTS_REPLACE);
All of this works (i.e. the file physically is moved into the correct place with correct name); however, the file displayed in the listings (i.e. /admin/content/files) still shows the incorrect temporary folder as the URI.
Basically the file in the listings page seems to be showing the original filepath and name* of a previously successfully moved* file.
If I load this file with incorrect URI, i.e. using the incorrect temp path, the data loads, but then will not have a file info (as it doesn't exist. Also clicking the filename by browser under listings will show page not found and the URL showing the old URL i.e. /system/temporary?file=XYZ.pdf).
If I load this file by correct URI, i.e. using the correct destination path, file not found - same if I go to the path directly in the browser.
It appears the managed file doesn't know it was moved. How to resolve this bug?
The docs for FileSystem::move say "Moves a file to a new location without database changes or hook invocation."
So you are going to need to update the file entity with the new values..
Try this, untested:
// Upload file
$upfile = $this->entityTypeManager->getStorage('file')->load($fid);
// Source and destination
$sourceUri = $this->fileSystem->realpath($upfile->getFileUri());
$destinationUri = $this->fileSystem->realpath(\Drupal::config('system.file')->get('default_scheme') . "://") . '/x/y/z/XYZ_NEW.pdf';
// Move and overwrite
$newFileName = $this->fileSystem->move($sourceUri, $destinationUri, FileSystemInterface::EXISTS_REPLACE);
// Set the new file path on the file entity.
$upfile->setFileUri($newFileName);
// Set the file to permanent if needed.
$upfile->setPermanent();
// Save entity with changes.
$upfile->save();
I did not test this though.
You can check the functions on the file entity in the docs here
It turns out the class based methods do not update the database
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21File%21FileSystem.php/function/FileSystem%3A%3Amove/8.9.x
The procedural version does
https://api.drupal.org/api/drupal/core%21modules%21file%21file.module/function/file_move/8.9.x

How to get all files from a media library in kentico?

I want to save all files paths inside of a media library folder in kentico.
I found this code for one file but I don't know which Class to use to get all content any advice, please.
MediaFileInfo updateFile = MediaFileInfoProvider.GetMediaFileInfo(library.LibraryID, "NewFolder/Image.png");
This should get all the files in a specific media library.
var files = MediaFileInfoProvider.GetMediaFiles().Where("FileLibraryID",QueryOperator.Equals, library.LibraryID);

read/download file using local absolute path

I have one file which is stored at D:/home/abc.pdf locally.
I have to read this file using AngularJs
var path="D:/home/abc.pdf";
var doc = document.createElement("a");
doc.href = path;
doc.download = path;
doc.click();
window.URL.revokeObjectURL(path);
I am not able to download this file.Giving error like Failed-Network error
That is impossible since local files are protected. Else you would be able to manipulate the hard drive as you wanted just by running a local HTML page.
So : if you want to get a file from the computer's hard drive, you have to use an <input> field and ask the user to upload the file using it.

The file download folder view in Struts 2

I'm creating a project of a school. I want to show the uploaded stuff by teachers to students.
But I also need to save the file in the folder which is named as faculty name. Student will be able to browse the main directory and after that he can go in the particular faculties folder.
How can I do it? Any suggestions will be appreciated.
For file upload I would start with example like in this answer. Moving files from temporary folder could be easily done by the file uploading action.
For browsing files in your case I would create an action that is able to navigate to the folder where the files are and get a list of files from that folder. Something like this
String file = application.getRealPath("/upload");
File f = new File(file);
String [] fileNames = f.list();
File [] fileObjects= f.listFiles();
for (int i = 0; i < fileObjects.length; i++) {
if(!fileObjects[i].isDirectory()){
String fname = file+fileNames[i];
out.println(fileNames[i]);
}
}
Then map this files to the JSP as links. When that link is clicked you can retrieve the actual path on the server when action is executed. What to do with the data, of course you can return stream result from the action that is used for streaming to the client browser. You can use docs examples from the Struts site or like in this example.
To navigate to the folder use parameters in GET request, that will be used to store current directory in session. You can change it if a user change the current directory from the view layer.

How to ignore a file in Meteor.js?

Needs to include this file (http://trailers.apple.com/appletv/us/js/application.js) in a Meteor.js project.
The file can't be in the public folder, and it has to be under PROJECT_ROOT/appletv/us/js/ folder.
But whenever I include the file, it crashes Meteor.
Any advice on how to ignore this arbitrary file in an arbitrary folder?
Just add
atv = {};
To the first line of this application.js
Other solution
Move your application.js to /lib, then create /lib/lib/hack.js
So your project will be:
<project>/lib/lib/hack.js
<project>/lib/application.js
<project>/*stuff*
And put
atv = {};
As the content of hack.js
Why can't it be in /public? /public is copied to the root of the server when deployed. So /public/appletv/us/js/application.js will be app.com/appletv/us/js/application.js when running.

Resources