Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rupanjan-baidya opened this issue May 10, 2017 · 3 comments
Closed

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

rupanjan-baidya opened this issue May 10, 2017 · 3 comments
Assignees

Comments

@rupanjan-baidya
Copy link

rupanjan-baidya commented May 10, 2017

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!!

@frankyn
Copy link
Member

frankyn commented Apr 3, 2018

Hello @rupanjanbaidya!

Are you still experiencing this issue?

Cheers!

@rupanjan-baidya
Copy link
Author

rupanjan-baidya commented Apr 3, 2018 via email

@frankyn
Copy link
Member

frankyn commented Apr 3, 2018

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.

@frankyn frankyn closed this as completed Apr 3, 2018
minherz pushed a commit that referenced this issue Nov 9, 2022
minherz pushed a commit that referenced this issue Nov 10, 2022
minherz pushed a commit that referenced this issue Nov 10, 2022
Sita04 pushed a commit that referenced this issue Nov 11, 2022
…uration to v1.2.0 (#657)

[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud.samples:shared-configuration](https://togithub.com/GoogleCloudPlatform/java-repo-tools) | `1.0.23` -> `1.2.0` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud.samples:shared-configuration/1.2.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud.samples:shared-configuration/1.2.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud.samples:shared-configuration/1.2.0/compatibility-slim/1.0.23)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud.samples:shared-configuration/1.2.0/confidence-slim/1.0.23)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>GoogleCloudPlatform/java-repo-tools</summary>

### [`v1.2.0`](https://togithub.com/GoogleCloudPlatform/java-repo-tools/compare/v1.0.24...v1.2.0)

[Compare Source](https://togithub.com/GoogleCloudPlatform/java-repo-tools/compare/v1.0.24...v1.2.0)

### [`v1.0.24`](https://togithub.com/GoogleCloudPlatform/java-repo-tools/compare/v1.0.23...v1.0.24)

[Compare Source](https://togithub.com/GoogleCloudPlatform/java-repo-tools/compare/v1.0.23...v1.0.24)

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-recaptchaenterprise).
Sita04 pushed a commit that referenced this issue Nov 15, 2022
…uration to v1.2.0 (#657)

[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud.samples:shared-configuration](https://togithub.com/GoogleCloudPlatform/java-repo-tools) | `1.0.23` -> `1.2.0` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud.samples:shared-configuration/1.2.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud.samples:shared-configuration/1.2.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud.samples:shared-configuration/1.2.0/compatibility-slim/1.0.23)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud.samples:shared-configuration/1.2.0/confidence-slim/1.0.23)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>GoogleCloudPlatform/java-repo-tools</summary>

### [`v1.2.0`](https://togithub.com/GoogleCloudPlatform/java-repo-tools/compare/v1.0.24...v1.2.0)

[Compare Source](https://togithub.com/GoogleCloudPlatform/java-repo-tools/compare/v1.0.24...v1.2.0)

### [`v1.0.24`](https://togithub.com/GoogleCloudPlatform/java-repo-tools/compare/v1.0.23...v1.0.24)

[Compare Source](https://togithub.com/GoogleCloudPlatform/java-repo-tools/compare/v1.0.23...v1.0.24)

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-recaptchaenterprise).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants