Load from a URI

GroupDocs.Metadata for Java can load a document straight from a web resource. Pass a java.net.URI to the Metadata constructor, and you don’t have to download the file yourself.

The document is downloaded into memory and then loaded the same way as a document loaded from a stream.

Loading a document from a URI

The following code sample shows how to load an image from a URL and read its EXIF properties.

advanced_usage.loading_files.LoadFromUri

// The document is downloaded into memory and then loaded like a stream
URI uri = URI.create("https://raw.githubusercontent.com/groupdocs-metadata/GroupDocs.Metadata-for-Java/master/Examples/Resources/SampleFiles/Input/exif.jpg");

try (Metadata metadata = new Metadata(uri)) {
    JpegRootPackage root = metadata.getRootPackageGeneric();
    System.out.println(root.getFileType().getFileFormat());

    if (root.getExifPackage() != null) {
        System.out.println(root.getExifPackage().getMake());
        System.out.println(root.getExifPackage().getModel());
    }
}

Loading a document of a specific format from a URI

Use the Metadata(URI, LoadOptions) constructor to set the file format explicitly or to pass a password.

RAR, 7z, TAR, AAR, GZIP, BZ2, XZ and Zstandard archives are recognized by the file extension, and a URI does not give the library a file name. Set the format of such an archive explicitly, otherwise the archive is not recognized correctly (a RAR archive, for example, is detected as an MP3 file).

URI uri = URI.create("https://raw.githubusercontent.com/groupdocs-metadata/GroupDocs.Metadata-for-Java/master/Examples/Resources/SampleFiles/Input/input.rar");

try (Metadata metadata = new Metadata(uri, new LoadOptions(FileFormat.Rar))) {
    RarRootPackage root = metadata.getRootPackageGeneric();
    System.out.println(root.getRarPackage().getTotalEntries());

    for (RarFile file : root.getRarPackage().getFiles()) {
        System.out.println(file.getName());
    }
}
Note
The whole document is downloaded into memory before it is processed. For large files, consider downloading them to a local disk first and loading them from the path.

More resources

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document metadata management App

Along with a full featured Java library we provide simple, but powerful free Apps.

You are welcome to view and edit metadata of PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, emails, images and more with our free online Free Online Document Metadata Viewing and Editing App.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.