minio / minio-java

MinIO Client SDK for Java
https://docs.min.io/docs/java-client-quickstart-guide.html
Apache License 2.0
1.11k stars 484 forks source link

MonioClient write/read file exception when filename has special charactor such as ;,u&. #355

Closed dreamquster closed 8 years ago

dreamquster commented 8 years ago

filename:u=2068517125,4062313322&fm=21&gp=0.jpg error message: time="2016-03-09T16:26:31+08:00" level=error msg="CreateObject failed." Error={The request signature we calculated does not match the signature you provided fs.SignatureDoesNotMatch [{296 C:/mygo/src/github.com/minio/minio/pkg/fs/fs-object. go fs.Filesystem.CreateObject map[]} {200 C:/mygo/src/github.com/minio/minio/object-handlers.go main.CloudStorageAPI.Put ObjectHandler map[]}] map[host.lang:go1.5.1 mem.used:2.8MB mem.heap.used:2.8MB mem.heap.total:3.8MB host.arch:amd64 host .name:PC-201512241034 host.cpus:8 mem.total:7.1MB host.os:windows]}

harshavardhana commented 8 years ago

@dreamquster - is it possible to reproduce this consistently? can you provide a sample program that we can use to reproduce this ?

Thank you

dreamquster commented 8 years ago
import io.minio.MinioClient;
import io.minio.Result;
import io.minio.errors.ErrorResponseException;
import io.minio.errors.InputSizeMismatchException;
import io.minio.errors.InsufficientDataException;
import io.minio.errors.InternalException;
import io.minio.errors.InvalidArgumentException;
import io.minio.errors.InvalidBucketNameException;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import io.minio.errors.NoResponseException;
import io.minio.messages.Bucket;
import io.minio.messages.Item;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.xmlpull.v1.XmlPullParserException;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

public class OminoTest {

    private String host = "http://192.168.16.90:9000";
    private String accessKey = "BF3GCGMOO8T6XFAJXCIN";
    private String secretAccessKey = "hH2PTtIr63fWur9/p4wWi3ce5osFed973q5C5GjD";

    @Test
    public void uploadPictures() throws InvalidPortException, InvalidEndpointException, IOException, InvalidKeyException, NoSuchAlgorithmException, InsufficientDataException, InternalException, NoResponseException, InvalidBucketNameException, XmlPullParserException, ErrorResponseException, InputSizeMismatchException, InvalidArgumentException {
        String filePath = "C:\\Users\\Administrator\\Pictures\\picturestest\\u=2677687249,4067068704&fm=21&gp=0.jpg";
        MinioClient s3client = new MinioClient(host, accessKey, secretAccessKey);
        File uploadFile = new File(filePath);
        ByteArrayInputStream bais = new ByteArrayInputStream(FileUtils.readFileToByteArray(uploadFile));

        List<Bucket> buckets = s3client.listBuckets();
        for (Bucket bucket: buckets) {
            System.out.println(bucket.name());
            Iterable<Result<Item>> headPics = s3client.listObjects(bucket.name());
            for (Result<Item> result : headPics) {
                Item item = result.get();
                System.out.println(item.lastModified() + ", " + item.size() + ", " + item.objectName());
                InputStream stream = s3client.getObject(bucket.name(), item.objectName());
                byte[] buf = new byte[16384];
                int bytesRead;
                while ((bytesRead = stream.read(buf, 0, buf.length)) >= 0) {
                    System.out.println(new String(buf, 0, bytesRead));
                }
                stream.close();
            }
        }
        s3client.putObject("personal", uploadFile.getName(), bais, bais.available(), MediaType.APPLICATION_OCTET_STREAM_VALUE);
        bais.close();
    }
}
harshavardhana commented 8 years ago

Thanks, will let you know..

harshavardhana commented 8 years ago

@dreamquster this seems to be working fine with latest minio release and minio-java can you validate again? here is my test program

import io.minio.MinioClient;
import io.minio.Result;
import io.minio.errors.ErrorResponseException;
import io.minio.errors.InputSizeMismatchException;
import io.minio.errors.InsufficientDataException;
import io.minio.errors.InternalException;
import io.minio.errors.InvalidArgumentException;
import io.minio.errors.InvalidBucketNameException;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import io.minio.errors.NoResponseException;
import io.minio.messages.Bucket;
import io.minio.messages.Item;
import org.xmlpull.v1.XmlPullParserException;

import java.io.*;
import java.nio.file.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

public class OminoTest {
    public static void main(String[] args) throws InvalidPortException, InvalidEndpointException, IOException, InvalidKeyException, NoSuchAlgorithmException, InsufficientDataException, InternalException, NoResponseException, InvalidBucketNameException, XmlPullParserException, ErrorResponseException, InputSizeMismatchException, InvalidArgumentException {
        String host = "http://localhost:9000";
        String accessKey = "WLGDGYAQYIGI833EV05A";
        String secretAccessKey = "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF";

        String filePath = "u=2677687249,4067068704&fm=21&gp=0.jpg";
        MinioClient s3client = new MinioClient(host, accessKey, secretAccessKey);
        InputStream bais = Files.newInputStream(Paths.get(filePath));
        List<Bucket> buckets = s3client.listBuckets();
        for (Bucket bucket: buckets) {
            System.out.println(bucket);
        }
        s3client.putObject("testbucket", filePath, bais, bais.available(), "application/octet-stream");
        bais.close();
    }
}
harshavardhana commented 8 years ago

Closing as its not reproducible anymore.