Search in sources :

Example 1 with ContentFile

use of com.salesmanager.shop.model.content.ContentFile in project shopizer by shopizer-ecommerce.

the class ContentAdministrationApi method upload.

/**
 * works with file manager (javascript client)
 * @param files
 * @param merchantStore
 * @param language
 */
@PostMapping(value = "/private/content/images/add", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
@ResponseStatus(HttpStatus.CREATED)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public FileStatus upload(@RequestParam(value = "qqfile", required = true) MultipartFile qqfile, @RequestParam(value = "qquuid", required = true) String qquuid, @RequestParam(value = "qqfilename", required = true) String qqfilename, @RequestParam(value = "qqtotalfilesize", required = false) Long qqtotalfilesize, @RequestParam(value = "parentPath", required = false) String parentPath, @RequestParam(value = "qqpartindex", required = false) Integer qqpartindex, @RequestParam(value = "qqtotalparts", required = false) Integer qqtotalparts, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
    if (!fileNameUtils.validFileName(qqfilename)) {
        FileStatus fs = new FileStatus();
        fs.setError("Invalid filename");
        fs.setSuccess(false);
        return fs;
    }
    ContentFile cf = new ContentFile();
    cf.setContentType(qqfile.getContentType());
    cf.setName(qqfilename);
    try {
        cf.setFile(qqfile.getBytes());
        contentFacade.addContentFile(cf, merchantStore.getCode());
        return new FileStatus();
    } catch (IOException e) {
        // throw new ServiceRuntimeException("Error while getting file bytes");
        LOGGER.error("Error when uploadging file", e);
        FileStatus fs = new FileStatus();
        fs.setError(e.getMessage());
        fs.setSuccess(false);
        return fs;
    }
}
Also used : ContentFile(com.salesmanager.shop.model.content.ContentFile) IOException(java.io.IOException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 2 with ContentFile

use of com.salesmanager.shop.model.content.ContentFile in project shopizer by shopizer-ecommerce.

the class ContentApi method upload.

/**
 * Need type, name and entity
 *
 * @param file
 */
@PostMapping(value = "/private/file")
@ResponseStatus(HttpStatus.CREATED)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public void upload(@RequestParam("file") MultipartFile file, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
    ContentFile f = new ContentFile();
    f.setContentType(file.getContentType());
    f.setName(file.getOriginalFilename());
    try {
        f.setFile(file.getBytes());
    } catch (IOException e) {
        throw new ServiceRuntimeException("Error while getting file bytes");
    }
    contentFacade.addContentFile(f, merchantStore.getCode());
}
Also used : ContentFile(com.salesmanager.shop.model.content.ContentFile) IOException(java.io.IOException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 3 with ContentFile

use of com.salesmanager.shop.model.content.ContentFile in project shopizer by shopizer-ecommerce.

the class ContentApi method uploadMultipleFiles.

@PostMapping(value = "/private/files", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
@ResponseStatus(HttpStatus.CREATED)
@ApiImplicitParams({ // required = true,dataType = "MultipartFile",allowMultiple = true),
@ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public void uploadMultipleFiles(@RequestParam(value = "file[]", required = true) MultipartFile[] files, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
    for (MultipartFile f : files) {
        ContentFile cf = new ContentFile();
        cf.setContentType(f.getContentType());
        cf.setName(f.getName());
        try {
            cf.setFile(f.getBytes());
            contentFacade.addContentFile(cf, merchantStore.getCode());
        } catch (IOException e) {
            throw new ServiceRuntimeException("Error while getting file bytes");
        }
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ContentFile(com.salesmanager.shop.model.content.ContentFile) IOException(java.io.IOException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Aggregations

ContentFile (com.salesmanager.shop.model.content.ContentFile)3 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)3 IOException (java.io.IOException)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 MultipartFile (org.springframework.web.multipart.MultipartFile)1