How to create a folder in Infura IPFS with Node - javascript

I'am trying to upload a folder of json files to infura. If i try to upload them one by one I have no issue. But what I'am trying to achieve is something like this:
IPFSHostname://QmcUHTMEqc4pQvyToVhA3g8QjKGavhD56mh9rtSXWxQULx/folder_name/2.json
And basically add all the files to that url, where the last param would be the file name. Is this even possible?

Related

How to download the complete project structure from cdnjs using Python

I want to download the complete project from the cdnjs cloud to local folder.
I have tried this:
import requests
files = requests.get("https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML%2CSafe.js&ver=4.1")
with open("mathjax.js","w") as file:
file.write(files.text)
Now this download the js file. When I tried using the same code to get the project instead of the js file, the output was weird.
So I tried using the cdnjs and check what happens when I use cdnjs cloud and when I use local file.
I have got this difference as shown in the images:
Using cdnjs:
Using Local file:
How I can get the similar structure as I get when I use cdnjs?
Kindly, advise me.
The URL you are providing to requests module is just the URL of one file MathJax.js, that is why you are getting only that file as output.
What you want is to download the complete directory mathjax/2.7.5/. However, if we request the whole directory, the server forbids such requests.
An alternate approach is to get relative paths of all the files from the main directory, which you already have as you showed in image. You can then download each of the file independently and store it into its respective folder. You'll have the whole directory ready at the end.
Try the following code for this purpose.
import requests
import os
baseUrl="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/" #Base URL for the main directory
#List containing relative paths of all required files
relativePaths=['config/Safe.js?V=2.7.5',
'config/TeX-AMS-MML_HTMLorMML.js?V=2.7.5',
'extensions/Safe.js?V=2.7.5',
'jax/output/SVG/fonts/TeX/fontdata.js?V=2.7.5',
'jax/output/SVG/jax.js?V=2.7.5',
'MathJax.js?config=TeX-AMS-MML_HTMLorMML%2CSafe.js&ver=4.1']
parentDir='\\'.join(baseUrl.split('/')[-3:]) #Parent directory from URL
for path in relativePaths: #For all files
req=requests.get(baseUrl+path) #forming url
filename=path.split("/")[-1].split("?")[0] #extracting filename out of url
directory=os.path.join(parentDir,"\\".join(path.split('/')[:-1])) #Extracting directories path for local path formation
if not os.path.exists(directory): #Creating local direcories if they do not exist
os.makedirs(directory)
with open(os.path.join(directory,filename),"wb+") as file: #Storing results into files
file.write(req.content)
Local Directory Structure Output:
Beyond iterating over a defined list of files, you could also look at a couple of other options that could take a more dynamic approach to fetch files from the CDN.
cdnjs is powered by a GitHub repository, so you could explore cloning it and extracting files (I'd recommend use sparse-checkout if you do this due to repo size) or you could look at using the GitHub API to navigate the repository an extract files: github.com/cdnjs/cdnjs/tree/master/ajax/libs/mathjax/2.7.5
We actually have an API available for cdnjs, which allows you to rather easily get all the files within a version of a library. Using that list, you could then perform a similar iterative solution to what Hamza suggested to get a copy of all the files locally: https://api.cdnjs.com/libraries/mathjax?fields=assets (annoyingly we've not yet implemented API navigation per version)
Hope that helps!
Matt, cdnjs maintainer.

Is there any way to upload folders using testcafe?

I have to write an e2e test for folder upload by drag-drop functionality in my portal using testcafe. I know there is a method setFilesToUpload() to upload files but is there any method using which we can upload a folder/directory structure?
At present, you cannot specify a folder for the setFilesForUpload action.
You need to specify all file paths in the folder.
Here is an example:
await t
.setFilesToUpload('#upload-input', [
'folder1/1.jpg',
'folder1/2.jpg',
'folder1/3.jpg'
])
I've created a suggestion regarding your case - https://github.com/DevExpress/testcafe/issues/3206. You can track it to be notified of our progress.

How to upload folder in php

Hi i wanted to upload folder and move to some destination is it possible doing in php ? or at least i can read the folder name and create same folder in divination and copy all files into created folder.
You can do this with the new HTML5 directory capabilities. Just put the directory attributes in your input field. After you got the directory server-side, you can do everything you want with it.
URL for a simple guide:
http://www.w3bees.com/2013/03/directory-upload-using-html-5-and-php.html

Is it possible to extracz a zip file by file to file

Hy
I have a question, is it possible to unzip a file via php but by file to file? I read some some zip Exempels in the php Manuals but i need a Way to extracz one file and than the other file.
For example:
I have a zip file with many Folders and in this Folder are some pictures. Now i want to extracz the First zip item and check:
If it is a Folder
If true than create a new file, extracz the Folder, create a new Folder in this Folder and save there the new file
If it is a file, than check size and Type
If this is correct than do something with this file
Next item
I als wantask if it is possible to check via javascript the zip file?
I readed something about a zip Library
I only want to read all files and check size and Type before uploaded

Combine all files in a folder as pdf

My current problem is that starting from the root folder I have to look into each folder and if one file exists then save it as a pdf with the folder name in a different location. If more then one file exists then combine this into one file, save it as a pdf with the folder name in a different location.
Example:
- Root Folder
- Folder1
- FileA.tif
- FileB.tif
- Folder2
- FileC.tif
- Result Folder
- Folder1.pdf (Contains FileA.tif and FileB.tif combined into one pdf)
- Folder2.pdf (Contains FileC.tif as pdf)
I am currently using Acrobat 9 Professional. I know I can do this manually, but I have to do this for hundreds of folders and each folder has one or more files.
My preffered solution would be in Acrobat Javascript on Windows XP.
Somethings that I am trying to figure out is if I can do some sort of:
For each folder in Root Folder
For each file in folder (Save the folder name too)
Combine files (I think I can mange this based on some examples I have seen)
I think that would give me a good start.
Any help would be greatly appreciated.
GhostView is a command-line program that can manipulate PDF files. Years ago, I used this to concatenate thousands of PDF files into a single PDF for download. It can convert multiple file types to PDF, plus you can apply all of the PDF security options to your final PDF as needed. You'll need the commercial version if you're packaging this for a product.
I am trying to solve the same problem here.
You need to install GhostScript and use some bat file to do the job.
I started to write this:
#echo off
set folpath=%~dp0
set PROG="c:\Program Files\gs\gs9.04\bin\gswin64"
set OUT= "%folpath%Combined.pdf"
pushd "%~dp0"
call %PROG% -o %OUT% -sOUTPUTFILE="%folpath%Merged.pdf" -dBATCH "%folpath%doc2.pdf" "%folpath%doc1.pdf"
pause
But it is not ready :)

Categories

Resources