Esempio n. 1
0
  protected byte[] getImageBytes(UploadRequest uploadRequest, String fieldNameValue)
      throws Exception {

    File file = uploadRequest.getFile(fieldNameValue + "File");

    byte[] bytes = FileUtil.getBytes(file);

    if (ArrayUtil.isNotEmpty(bytes)) {
      return bytes;
    }

    String url = uploadRequest.getParameter(fieldNameValue + "URL");

    long imageId = GetterUtil.getLong(HttpUtil.getParameter(url, "img_id", false));

    Image image = ImageLocalServiceUtil.fetchImage(imageId);

    if (image == null) {
      return null;
    }

    return image.getTextObj();
  }
Esempio n. 2
0
  protected String getImageFieldValue(UploadRequest uploadRequest, String fieldNameValue) {

    try {
      byte[] bytes = getImageBytes(uploadRequest, fieldNameValue);

      if (ArrayUtil.isNotEmpty(bytes)) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("alt", uploadRequest.getParameter(fieldNameValue + "Alt"));
        jsonObject.put("data", UnicodeFormatter.bytesToHex(bytes));

        return jsonObject.toString();
      }
    } catch (Exception e) {
    }

    return StringPool.BLANK;
  }