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

Uploading an image file via the Add Product flow fails #32

Closed
moustaphastar opened this issue Sep 9, 2021 · 0 comments · Fixed by #33
Closed

Uploading an image file via the Add Product flow fails #32

moustaphastar opened this issue Sep 9, 2021 · 0 comments · Fixed by #33
Assignees
Labels
bug Something isn't working

Comments

@moustaphastar
Copy link
Collaborator

Description
Product images can't be uploaded on admin panel while trying to add a product using the "Ürün Ekle" flow.

The front end app receives a 500 status code from the back end app which throws a NullPointerException at retrieving Google credentials through the uploadFile method of the FirebaseFileServiceImpl class. Inside this method, getResourceAsStream method call is passed an argument as "zuri-petshop-firebase.json" (non-existent) instead of "firebase.json" (existent).

@Service
public class FirebaseFileServiceImpl implements FirebaseFileService {
// ...
    @Override
    public String uploadFile(InputStream is, String contentType, String path, String fileName) throws IOException {
        InputStream serviceAccount = getClass()
                .getClassLoader()
                .getResourceAsStream("zuri-petshop-firebase.json");  // <= Correct filename is "firebase.json"
        Storage storage = StorageOptions.newBuilder()
                .setCredentials(GoogleCredentials.fromStream(serviceAccount)) // <= Throws NullPointerException
                .setProjectId(PETSHOP_FIREBASE_PROJECT_ID).build().getService();
// ...
    }
}

Steps to Reproduce

  • Login to admin panel.
  • Add a category if none exists.
  • Upload an image file for a product using the "Ürün Ekle" flow .

Expected Result
The product image file is uploaded successfully to Firebase.

Actual Result
Upload fails. Admin panel receives a 500 status code from the back end app and the back end app throws a NPE.

Error Message

2021-09-09 03:47:24.233 ERROR 6832 --- [nio-8081-exec-4] c.t.p.v.h.ApplicationExceptionHandler    : Exception : class java.lang.NullPointerException: null

java.lang.NullPointerException: null
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:892) ~[guava-30.1.1-android.jar:na]
	at com.google.api.client.util.Preconditions.checkNotNull(Preconditions.java:125) ~[google-http-client-1.39.2.jar:1.39.2]
	at com.google.auth.oauth2.GoogleCredentials.fromStream(GoogleCredentials.java:151) ~[google-auth-library-oauth2-http-0.26.0.jar:na]
	at com.google.auth.oauth2.GoogleCredentials.fromStream(GoogleCredentials.java:134) ~[google-auth-library-oauth2-http-0.26.0.jar:na]
	at com.turkninja.petshop.file.impl.FirebaseFileServiceImpl.uploadFile(FirebaseFileServiceImpl.java:32) ~[classes/:na]
	at com.turkninja.petshop.v1.FileResource.uploadFile(FileResource.java:30) ~[classes/:na]
	
// ... Rest of the error message is omitted
@moustaphastar moustaphastar self-assigned this Sep 9, 2021
@moustaphastar moustaphastar added the bug Something isn't working label Sep 9, 2021
moustaphastar added a commit that referenced this issue Sep 9, 2021
@moustaphastar moustaphastar moved this from In progress to Done in Open Source Petshop Project Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

1 participant