GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Storage:: Clicking on "Public Link" downloads the files · Issue #657 · GoogleCloudPlatform/java-docs-samples

Storage:: Clicking on "Public Link" downloads the files #657

New issue
Copy link
New issue
Copy link
Closed
Closed
Storage:: Clicking on "Public Link" downloads the files#657
Copy link
Assignees
frankyn

Description

@rupanjan-baidya
rupanjan-baidya
opened on May 10, 2017
Issue body actions

In which file did you encounter the issue?

https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/storage/json-api/src/main/java/StorageSample.java

Did you change the file? If so, how?

public static void uploadFile(String bucketName, String targetPath, String filePath) throws Exception {
	Storage storage = getStorage();
	StorageObject object = new StorageObject();
	object.setBucket(bucketName);
	File file = new File(filePath);
	InputStream stream = new FileInputStream(file);
	try {
		// String contentType =
		// URLConnection.guessContentTypeFromStream(stream);
		InputStreamContent content = new InputStreamContent("image/jpeg", stream);
		Storage.Objects.Insert insert = storage.objects().insert(bucketName, null, content);
		insert.setName(targetPath + file.getName());
		insert.execute();
	} finally {
		stream.close();
	}
}

public static void uploadFile(String name, String targetPath, String contentType, File file, String bucketName)
		throws IOException, GeneralSecurityException, Exception {
	InputStreamContent contentStream = new InputStreamContent(contentType, new FileInputStream(file));
	contentStream.setLength(file.length());
	StorageObject objectMetadata = new StorageObject().setName(targetPath + name)
			.setAcl(Arrays.asList(new ObjectAccessControl().setEntity("allUsers").setRole("READER")));

	Storage client = getStorage();
	Storage.Objects.Insert insertRequest = client.objects().insert(bucketName, objectMetadata, contentStream);
	insertRequest.execute();
}

private static Storage getStorage() throws Exception {
	if (storage == null) {
		HttpTransport httpTransport = new NetHttpTransport();
		JsonFactory jsonFactory = new JacksonFactory();
		List<String> scopes = new ArrayList<String>();
		scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL);
		// Collection<String> scopes = StorageScopes.all();
		Credential credential = new GoogleCredential.Builder().setTransport(httpTransport)
				.setJsonFactory(jsonFactory).setServiceAccountId(getProperties().getProperty(ACCOUNT_ID_PROPERTY))
				.setServiceAccountPrivateKeyFromP12File(
						new File(getProperties().getProperty(PRIVATE_KEY_PATH_PROPERTY)))
				.setServiceAccountScopes(scopes).build();

		storage = new Storage.Builder(httpTransport, jsonFactory, credential)
				.setApplicationName(getProperties().getProperty(APPLICATION_NAME_PROPERTY)).build();
	}
	return storage;
}

public static void main(String[] args) throws Exception {
CloudStorage.uploadFile("hng-static", "temp/", "/Users/rupanjan/Downloads/15676285_10158033346085311_1317913818452680683_o.jpg");
CloudStorage.uploadFile("15676285_10158033346085311_1317913818452680683_o.jpg", "temp/", "image/jpeg", new File("/Users/rupanjan/Downloads/15676285_10158033346085311_1317913818452680683_o.jpg"),
"hng-static");
}

Describe the issue

I am able to upload the file successfully, but whenever, I click on that "Public Link", it downloads automatically. My intention was to share it for all user with read access. N.B. If I am uploading the file manually from browser, I am able to open the file in browser, but when I upload it programically, it downloads everytime I click on "Public Link"

Please correct me if I am missing anything!!

Activity

  1. jabubake
    assigned
    frankyn
    on Apr 3, 2018
  2. frankyn commented on Apr 3, 2018

    @frankyn
    frankyn
    on Apr 3, 2018
    Contributor
    More actions

    Hello @rupanjanbaidya!

    Are you still experiencing this issue?

    Cheers!

  3. rupanjan-baidya commented on Apr 3, 2018

    @rupanjan-baidya
    rupanjan-baidya
    on Apr 3, 2018 via email
    Author
    More actions
    No .. I did work out for me somehow ... can't remember exactly ... it was 1 year back I believe ...
    …
    On Wed, Apr 4, 2018 at 12:24 AM, Frank Natividad ***@***.***> wrote: [image: Boxbe] <https://www.boxbe.com/overview> Frank Natividad ( ***@***.***) is not on your Guest List <https://www.boxbe.com/approved-list?tc_serial=38045805309&tc_rand=914348953&utm_source=stf&utm_medium=email&utm_campaign=ANNO_MWTP&utm_content=001&key=b7lCGA6fKOpyUptBwwqpYTLg952AeZ5sU%2Fn4QJvgvUc%3D&token=%2BUVCrnGrtsEKeq24kiIgYZrPN7PMz0MbB9rr0o1lBCA2j0qFtM4CtZ6lSrWKc8hM> | Approve sender <https://www.boxbe.com/anno?tc_serial=38045805309&tc_rand=914348953&utm_source=stf&utm_medium=email&utm_campaign=ANNO_MWTP&utm_content=001&key=b7lCGA6fKOpyUptBwwqpYTLg952AeZ5sU%2Fn4QJvgvUc%3D&token=%2BUVCrnGrtsEKeq24kiIgYZrPN7PMz0MbB9rr0o1lBCA2j0qFtM4CtZ6lSrWKc8hM> | Approve domain <https://www.boxbe.com/anno?tc_serial=38045805309&tc_rand=914348953&utm_source=stf&utm_medium=email&utm_campaign=ANNO_MWTP&utm_content=001&dom&key=b7lCGA6fKOpyUptBwwqpYTLg952AeZ5sU%2Fn4QJvgvUc%3D&token=%2BUVCrnGrtsEKeq24kiIgYZrPN7PMz0MbB9rr0o1lBCA2j0qFtM4CtZ6lSrWKc8hM> Hello @rupanjanbaidya <https://github.com/rupanjanbaidya>! Are you still experiencing this issue? Cheers! — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#657 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AC8Y1j-EJGmN4-4ne5MO-kRvptuF5HgHks5tk8V_gaJpZM4NWgx_> .
  4. frankyn commented on Apr 3, 2018

    @frankyn
    frankyn
    on Apr 3, 2018
    Contributor
    More actions

    Apologies for the delay. Thanks for getting back to me!

    I'll close this out for now. I suspect it had to do with object content-type metadata not being set correctly, although not sure.

  5. frankyn
    closed this as completedon Apr 3, 2018
  6. minherz
    added 3 commits that reference this issue on Nov 9, 2022

    chore: release 0.122.4 (#658)

    83e7660

    chore: release 0.122.4 (#658)

    0a804ce

    chore: release 0.122.4 (#658)

    b5f37c6
  7. Sita04
    added 2 commits that reference this issue on Nov 11, 2022

    chore(deps): update dependency com.google.cloud.samples:shared-config…

    6bbe1de

    chore(deps): update dependency com.google.cloud.samples:shared-config…

    a068a76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @frankyn
    frankyn

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.