magento2 – Create new VPS memory images and download files to magento

My pages are very big with image and file upload.

So, I want to set up as a CDN from another Server2 VPS from the current Server1 VPS. This server will upload memory images and files.

I knew that Magento could change the URL storage of baseUrl and baseSecureUrl. However, I do not know how to map 2 servers and sync that.

Can someone suggest me to create such a memory step by step?

Sharepoint Online / 365 integration (uploading files) in the React app, which is hosted on Azure and WebApi C # .Net Core 2.2

I've been having trouble interacting / automating a way to upload files from a Web application created in React and upload files to a Sharepoint online site in a particular folder for several weeks. The WebApp is hosted in Azure and uses a C # .Net Core 2.2 as the backend.

I'm trying to use a kind of REST API to help me with this task. (May be activated in the frontend or in C # Core or C # MS FW .Net for the backend.)
I'm looking for a way to do this on the internet, but all tests have failed.

Anyone can give me insights, tips or advice on how to do this?

I'm trying:

  • Use code from Microsoft WebPage (Using jQuery).

  • When using PnP, but on my local host, a CORS issue is displayed (I am trying to interact with the client ID and the secret ID with Sharepoint).

Database implementation, hot files to organize

I'm trying to build a very small object database, not to learn a bit in my free time.
I have a data structure that stores my data in blocks of a certain size and combines it when more data is needed.
But now my problem is, if I do that, I need one file per object type that I want to save (the same goes for my B-tree index file). How would I design the database file to store different object types in the same one?

java – Encryption algorithm that encrypts and decrypts plain text and files from a specific directory

I have created an encryption and decryption algorithm that encrypts plain text using a particular encryption and decrypts it back to the original. That works perfect.

This was my code for a test and the examiner told me that the class structure is reversed as it is done right. In addition, it is sloppy in some places.

I want to know WHAT (or WHEN) about the structure of the classes is wrong. Does it look sloppy? Can someone help me identify any sites that lack Java coding best practices?

Can someone please read and tell me what's wrong with that and how I can improve the class structure?

I have a MyBuilder Class that creates an instance of MyAlgorithm,
MyAlgorithm has the methods to encrypt and decrypt text and adds another class called EncryptionAndDecryption where the actual logic of the algorithm is located.

Here is the code:

public class MyAlgorithm extends EncryptionAndDecryption {

    public enum Action {
        ENCRYPT,
        DECRYPT
    }

    protected MyAlgorithm(final String cipherCharSet) {
        super(cipherCharSet);
    }

    public String encryptText(final String cipher, final String plainText) {
        return encryptOrDecryptText(cipher, plainText, Action.ENCRYPT);
    }

    public String decryptText(String cipher, String encryptedText) {
        return encryptOrDecryptText(cipher, encryptedText, Action.DECRYPT);
    }

    public boolean encryptDirectory(String cipher, String baseDirectory) {
        Path root = Paths.get(baseDirectory);
        try {
            // Lazily traverse to all files from the given baseDirectory.
            Files.walk(root)
                    .filter(Files::isRegularFile)
                    .forEach(file -> encryptOrDecryptFile(cipher, file, baseDirectory, Action.ENCRYPT));
            return true;
        } catch (IOException e) {
            System.err.println("The provided baseDirectory cannot be found or is not readable: <" + baseDirectory + ">");
            return false;
        }
    }

    public boolean decryptDirectory(String cipher, String baseDirectory) {
        Path source = Paths.get(baseDirectory);
        try {
            Files.walk(source)
                    .filter(Files::isRegularFile)
                    .forEach(file -> encryptOrDecryptFile(cipher, file, baseDirectory, Action.DECRYPT));
            return true;
        } catch (IOException e) {
            System.err.println("The provided baseDirectory cannot be found or is not readable: <" + baseDirectory + ">");
            // e.printStackTrace();
            return false;
        }
    }
}

public class EncryptionAndDecryption {

    private final String CIPHER_CHAR_SET;
    private final String ENCRYPTED_DIR_SUFFIX = ".encrypted";
    private final String DECRYPTED_DIR_SUFFIX = ".decrypted";

    protected EncryptionAndDecryption(final String cipherCharSet) {
        this.CIPHER_CHAR_SET = cipherCharSet;
    }

    protected final String encryptOrDecryptText(final String cipher, final String inputText, final MyAlgorithm.Action action) {

        final int cipherSize = cipher.length();
        final int inputSize = inputText.length();
        StringBuilder targetBuilder = new StringBuilder();

        int cipherIndex = 0;
        for (int i = 0; i < inputSize; i++) {

            final int cipherTextPos = getIndexForChar(inputText.charAt(i));

            if(cipherTextPos < 0) {

                targetBuilder.append(inputText.charAt(i));

            } else {

                cipherIndex = cipherIndex == cipherSize ? 0 : cipherIndex;

                // current cipher character
                final char cipherChar = cipher.charAt(cipherIndex);
                // current rotated cipher set.
                final String ROTATED_CIPHER_SET = rotate(String.valueOf(cipherChar));

                if( action == MyAlgorithm.Action.ENCRYPT ) {
                    targetBuilder.append(ROTATED_CIPHER_SET.charAt(getIndexForChar(inputText.charAt(i))));
                } else {
                    int index = ROTATED_CIPHER_SET.indexOf(inputText.charAt(i));
                    targetBuilder.append(CIPHER_CHAR_SET.charAt(index));
                }

                cipherIndex++;
            }
        }
        return targetBuilder.toString();
    }

    protected final void encryptOrDecryptFile(final String cipher, final Path filePath, final String baseDirectory, final MyAlgorithm.Action action) {

        String sourceFilePath = filePath.toFile().getAbsolutePath();
        String pathAfterBaseDir = sourceFilePath.substring(baseDirectory.length()-1);
        String targetFileName = (action == MyAlgorithm.Action.ENCRYPT) ? baseDirectory + ENCRYPTED_DIR_SUFFIX + pathAfterBaseDir
                : baseDirectory + DECRYPTED_DIR_SUFFIX + pathAfterBaseDir;
        Path targetFile = Paths.get(targetFileName);

        try {
            // create target directory and target file.
            Files.createDirectories(targetFile.getParent());
            Files.createFile(targetFile);
        } catch (FileAlreadyExistsException e) {
        } catch (IOException e) {
            e.printStackTrace();
        }

        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        try {

            in = new BufferedInputStream(new FileInputStream(sourceFilePath));
            out = new BufferedOutputStream(new FileOutputStream((targetFileName)));

            byte() bytes = new byte(4096*4096); // reading 16KB at once
            int dataLength;

            while ((dataLength = in.read(bytes)) != -1) {
                for (int i = 0; i < dataLength ; i++) { // writing character by character, to prevent writing extra bytes.
                    String character = String.valueOf((char)bytes(i));
                    out.write(encryptOrDecryptText(cipher, character, action).getBytes());
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(in != null && out != null) {
                try {
                    in.close();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private String rotate(String onCharacter) {

        int beginIndex = CIPHER_CHAR_SET.indexOf(onCharacter);
        int endIndex = CIPHER_CHAR_SET.length();

        if(beginIndex == 0) {
            return CIPHER_CHAR_SET;
        } else {
            return CIPHER_CHAR_SET.substring(beginIndex, endIndex) + CIPHER_CHAR_SET.substring(0, beginIndex);
        }
    }

    private int getIndexForChar(char character) {
        try {
            return CIPHER_CHAR_SET.indexOf(character);
        } catch (StringIndexOutOfBoundsException e) {
            return character;
        }
    }
}


public class MyBuilder {

    private String CIPHER_CHAR_SET;

    private MyBuilder() {}

    public static MyBuilder builder() {
        return new MyBuilder();
    }

    public MyBuilder withCipherSet(String cipherSet) {
        this.CIPHER_CHAR_SET = cipherSet;
        return this;
    }

    public MyAlgorithm build() {
        return new MyAlgorithm(CIPHER_CHAR_SET);
    }
}

public class MyEncryptionApp {

    public static final String CIPHER_CHAR_SET = "abcdefghijklmnopqrstuvwxyz";

    public static void main(String args()) {
        if (args.length != 3) {
            System.out.println("Exact 3 parameters required - (action) (key) (target)");
            System.exit(1);
        }

        String action, key, target;
        action = args(0);
        key = args(1);
        target = args(2);

        MyAlgorithm myAlgorithm = MyBuilder.builder()
                .withCipherSet(CIPHER_CHAR_SET)
                .build();

        if ("encrypt".equalsIgnoreCase(action)) {
            System.out.println(myAlgorithm.encryptText(key, target));

        } else if ("decrypt".equalsIgnoreCase(action)) {
            System.out.println(myAlgorithm.decryptText(key, target));

        } else if ("encryptDir".equalsIgnoreCase(action)) {

            if(myAlgorithm.encryptDirectory(key, target)) {
                System.out.println("Directory encryption Successful");
            }

        } else if ("decryptDir".equalsIgnoreCase(action)) {

            if(myAlgorithm.decryptDirectory(key, target)) {
                System.out.println("Directory decryption Successful");
            }

        } else {
            System.out.println("action (" + action + ") not implemented");
        }

    }
}

Unauthorized Azure app (ERROR401) to download files from shared links in Sharepoint

I'm currently doing an integration that requires me to download files from shared links.

Users can create sharing links to their files in SharePoint. To download the file, just add download = 1 in the URL parameters.

My program (created from app registration) can download publicly set files. However, if restrictions are set, e.g. For example, if I have group-specific users, I get ERROR 401 Unauthorized even though I have already performed Oauth2 authentication (I can invoke other REST APIs to display folders, etc.).

I feel that if the links are restricted to a particular group, my client will not be recognized as the user I signed in with. I tried to increase the API permissions of my client for both delegated applications and applications, but it still does not work. Any help here?

Thank you in advance!

Loading KML files into the Javascript card of the brochure

This is the work code for entering KML files into the booklet card

// Load kml file
fetch('lotA.kml')
      .then( res => res.text() )
      .then( kmltext => {

            // Create new kml overlay
            parser = new DOMParser();
            kml = parser.parseFromString(kmltext,"text/xml");

            console.log(kml)

            const track = new L.KML(kml)
            map.addLayer(track)

            // Adjust map to show the kml
            const bounds = track.getBounds()
            map.fitBounds( bounds )

      })

fetch('lotB.kml')
      .then( res => res.text() )
      .then( kmltext => {

            // Create new kml overlay
            parser = new DOMParser();
            kml = parser.parseFromString(kmltext,"text/xml");

            console.log(kml)

            const track = new L.KML(kml)
            map.addLayer(track)

            // Adjust map to show the kml
            const bounds = track.getBounds()
            map.fitBounds( bounds )

      })

fetch('Schematic.kml')
      .then( res => res.text() )
      .then( kmltext => {

            // Create new kml overlay
            parser = new DOMParser();
            kml = parser.parseFromString(kmltext,"text/xml");

            console.log(kml)

            const track = new L.KML(kml)
            map.addLayer(track)

            // Adjust map to show the kml
            const bounds = track.getBounds()
            map.fitBounds( bounds )

      })

fetch('LotC.kml')
      .then( res => res.text() )
      .then( kmltext => {

            // Create new kml overlay
            parser = new DOMParser();
            kml = parser.parseFromString(kmltext,"text/xml");

            console.log(kml)

            const track = new L.KML(kml)
            map.addLayer(track)

            // Adjust map to show the kml
            const bounds = track.getBounds()
            map.fitBounds( bounds )

      })

fetch('LotD.kml')
      .then( res => res.text() )
      .then( kmltext => {

            // Create new kml overlay
            parser = new DOMParser();
            kml = parser.parseFromString(kmltext,"text/xml");

            console.log(kml)

            const track = new L.KML(kml)
            map.addLayer(track)

            // Adjust map to show the kml
            const bounds = track.getBounds()
            map.fitBounds( bounds )

      })

Is there a way to write this code shorter? I want to use it for multiple KML layers.

html – I am trying to create a form for uploading files for my website. I have code that does not work

I can not get this to work. Am I doing something wrong?

  $extensions= array("jpeg","jpg","png");

  if(in_array($file_ext,$extensions)=== false){
     $errors()="extension not allowed, please choose a JPEG or PNG file.";
  }

  if($file_size > 2097152) {
     $errors()='File size must be excately 2 MB';
  }

  if(empty($errors)==true) {
     move_uploaded_file($file_tmp,"images/".$file_name);
     echo "Success";
  }else{
     print_r($errors);
  }

}
?>

  
  • Sent file:
  • File size:
  • File type: